Today I faced a strange problem. I have an application which is the same for iPhone and iPad, it's an universal app, however I made two main view controllers, one for iPhone and one for iPad. I made the iPhone version first... then I copied some of the code to the iPad version. Everything seems to work fine except my logo UIImageView. I have a logo which slides down from off screen to the center of navigation bar. Before the animation I set up the UIImageView to be off screen, so then it could slide down. But, even if I put any random value in the x and y of uiimageview frame, it is still at 0, 0. It's the same code I have on iPhone and it's working ok.
Here is my initialization.
UIImage *logoText = [UIImage imageNamed:@"logotext.png"];
[logoTextView setUserInteractionEnabled:YES];
logoTextView = [[UIImageView alloc] init];
// I already tried [[UIImageView alloc] initWithFrame:CGRectMake......];
logoTextView.frame = CGRectMake(389, -100, logoText.size.width, logoText.size.height);
logoTextView.image = logoText;
logoTextView.center = CGPointMake(389, -100);
logoTextView.alpha = 1;
[logoTextView addGestureRecognizer:resetGesture];
// [logoTextView setBackgroundColor:[UIColor whiteColor]];
[self.view insertSubview:logoTextView atIndex:10];
This should actually position the UIImageView in the center and 100px off the screen. But nothing happens. It is still 0, 0. I tried it all ways I know, nothing really works...
Does somebody know, what to do? It would really help me. :)
EDIT
I have just found the solution... I don't know why but this only works if its in a new method... weird.
- (void)logoShow {
UITapGestureRecognizer *resetGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resetValues)];
UIImage *logoText = [UIImage imageNamed:@"logotext@2x.png"];
logoTextView = [[UIImageView alloc] initWithFrame:CGRectMake(389, -50, logoText.size.width/1.35, logoText.size.height/1.35)];
logoTextView.center = CGPointMake(389, -50);
logoTextView.image = logoText;
logoTextView.alpha = 1;
[logoTextView addGestureRecognizer:resetGesture];
[self.view insertSubview:logoTextView atIndex:15];
// LOGO TEXT ANIMATION
[UIView beginAnimations:@"Logo Text Animation" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelay:4.5];
[UIView setAnimationDuration:0.5];
logoTextView.alpha = 1;
logoTextView.center = CGPointMake(389, 22);
[UIView commitAnimations];
[logoTextView setUserInteractionEnabled:YES];
}