您的位置:首页 > 其它

视图切换总结

2012-08-26 17:07 281 查看
1、利用ModalViewController切换View

当程序中含有多个 view,需要在之间切换的时候,可以使用 UINavigationController,或者是 ModalViewController。UINabigationController 是通过向导条来切换多个 view。而如果 view 的数量比较少,且显示领域为全屏的时候,用 ModalViewController 就比较合适(比如需要用户输入信息的view,结束后自动回复到之前的view)。

ModalViewController 并不像 UINavigationController 是一个专门的类,使用 UIViewController 的 presentModalViewController 方法指定之后就是 ModalViewController 了。

调用 UIViewController 的 dismissModalViewController:Animated: 方法就可以退出

在A里面直接跳到B中 [A presentModalViewController:B animated:YES];

在B中可以通过 返回到A [self dismissModalViewControllerAnimated:YES]

UINavigationController 的 pushViewController: animated:

UIViewController的presentModalViewController: animated:

增加 Notification

post Notification

addSubview

b bringSubviewToFront

insertSubview b atIndex 0

removeview a

IPhone中视图切换,网上常见的方法都是用viewcontrol,在viewcontrol中插入不同的视图实现,见下面的代码

[self.view insertSubview:self.mainview.view atIndex:0];

只要切换不同的mainview就可以实现,网上常见的方法也是如此,不过我却想用另外一种方法,就是直接操作window,

在window中切换view,实现方法如下:

[viewController.view removeFromSuperview];

[window addSubview:viewset.view];

其中viewController是当前窗口,首先从 父窗口中移除,然后调用window addSubview方法即可。

不过使用第二个方法,出现了一个问题就是原来的主窗口显示正常,但是切换到第二个窗口是,窗口被电池栏给覆盖了,显得很奇怪,目前无解。

1.首先用pushViewController切换到下一个视图的,切换回来用popViewControllerAnimated

也就是:

切换视图:[self.tabBarController.navigationController pushViewController:_appMore animated:YES];

或者[self.navigationController pushViewController:_appMore animated:YES];

切换回来的时候用:

[self.navigationController popViewControllerAnimated:YES];

2.两个view之间切换:

假设aimview是目标视图

currentview是当前视图

首先移除当前view

[currentview.view removeFromSuperview];

[self.view insertSubview:aimview.view atIndex:0]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: