我有一个 UIViewController 1 UIButton(添加为子视图),在我按下 Button(见下图 1)之后,在它上面添加了另一个 UIViewController 2,在一些操作后从下到上动画:
[[[UIApplication sharedApplication] keyWindow] addSubview:self.view];
而且它重叠UIButton
,我怎样才能添加它没有覆盖的这个子视图UIButton
(见下图2)
图1:
图。2:
我有一个 UIViewController 1 UIButton(添加为子视图),在我按下 Button(见下图 1)之后,在它上面添加了另一个 UIViewController 2,在一些操作后从下到上动画:
[[[UIApplication sharedApplication] keyWindow] addSubview:self.view];
而且它重叠UIButton
,我怎样才能添加它没有覆盖的这个子视图UIButton
(见下图2)
图1:
图。2:
您尚未显示动画代码,但我假设您将子视图添加到屏幕外,然后更改它的框架(动画)以将其滑入视图。
改为使用添加新的子视图insertSubview:belowSubview:
,将您的按钮作为第二个参数传递。这样按钮将与新视图重叠,而不是相反。addSubview:
总是把新观点放在任何其他观点之上。
编辑
从您的评论看来,您正在使用将第二个视图控制器添加到屏幕上,presentModalViewController:
因此上述方法将不起作用。据我所知,如果您以这种方式呈现它,则无法将原始视图控制器中的元素保留在新视图控制器的视图之上。
您可能必须创建一个新UIWindow
的并将其设置windowLevel
为UIWindowLevelAlert
按住您的按钮。这将使其保持在下面的任何视图之上。将此窗口作为子视图添加到主窗口。
{
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];
}
将此代码放在按钮操作中,并将 secondViewController 替换为您的 ViewController。