开发者

Second View shifts upward when flipped from First View

I am building an ap in which I need to remove the present view from the开发者_StackOverflow中文版 superView and load another one. But the new loaded view shifts upward. Also when the firstView is again loaded, it loads perfectly.

Could anyone possible suggest something to get rid of this issue.

Following is the method I am using to flip the view to secondView

-(void) flipToBack
{
CreateMessageViewController *oSecondView = [[CreateMessageViewController alloc] initWithNibName:@"CreateMessageViewController" bundle:nil];
[self setMsgViewController:oSecondView];
[oSecondView release];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];

[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}

Thanks in advance!!

Looking forward to your kind responses.

thanks


There is not much I can tell without looking at the big picture. Check the frames in the IB to see if they are correctly set. Is this code from your appDelegate? Does viewController have a toolbar shown on his view? Maybe your view is shifted the exact pixels your toolbar height is?


Got it. It's happening due to the IB settings. So in IB your viewController has a statusBar and your view has a height of 460 (for iPhone) not 480. The 20 points are the statusBar height. When transitioning to the second view, its rect is {0,0,320,460} so the view is positioned behind the application's statusBar and you are missing 20 points from the bottom.

To get around this you need to:

  1. Go into IB and set the CreateMessageViewController's statusBar to Unspecified.
  2. Go into the view size section and set the view's height to 480 (for iPhone).

Now your CreateMessageViewController's view will show properly.


After long time playing around with the code and IB, I found the bug. It was corrected as

Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.

And the code changes to

-(void) flipToBack
 {
     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:0.8];
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];

     [viewController.view removeFromSuperview];
     [tabBarController.view removeFromSuperview];
     [self.window addSubview:[msgViewController view]];
     [UIView commitAnimations];
 }

Thanks to all who responded!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜