开发者

UIViewController present another UIViewController

I Have a UIViewController 1 on it UIButton (added as subview), after I pressed Button (see pic.1 below) on it adding another UIViewController 2 with animation from the bottom to top after some action:

[[[UIApplication sharedApplication] keyWindow] addSubview:self.view];

And it overlaps UIButton, how can I add this subview that it does not cover UIButton(see pic.2 be开发者_如何转开发low)

pic.1:

UIViewController present another UIViewController

pic. 2:

UIViewController present another UIViewController


You haven't shown the animation code but I assume you add the subview off-screen, then change it's frame (animated) to slide it into view.

Add the new subview using insertSubview:belowSubview: instead, passing your button as the second argument. This way the button will overlap the new view, instead of the other way round. addSubview: always puts the new view on top of any others.

EDIT

From your comments it seems that you're adding the second view controller to the screen using presentModalViewController: so the above method won't work. As far as I know there is no way to keep an element from the original view controller on top of the new view controller's view if you are presenting it this way.

You may have to create a new UIWindow and set it's windowLevel to UIWindowLevelAlert to hold your button. This will keep it on top of any of the views underneath. Add this window as a subview to the main window.


{
SecondViewController *objComing=[[SecondViewController alloc] init];
[self.view addSubview:objComing.view];

objComing.view.backgroundColor=[UIColor blueColor];

objComing.view.frame=CGRectMake(0,420, 320, 0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
objComing.view.frame=CGRectMake(0,0, 320, 420);

[UIView commitAnimations];

}

Put this code in the button action and replace secondViewController with your ViewController.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜