当iPhone处于标准“纵向”方向时,我将如何看到一个视图,并且在旋转到横向时切换到另一个视图(如图表或其他东西),反之亦然?当iPhone旋转时更改视图?
1
A
回答
3
禁用取向该视图(假设第一视图是横向)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)||(interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
然后将其添加到viewDidAppear
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
并添加此方法某处
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
// Present View Controller here
break;
default:
break;
};
}
在另一种观点上做同样的事情,但是对于风景画来说,这种做法是背道而驰的现在的肖像的肖像。
不要忘记取消注册通知。
(或者使用带有两个控件,但没有酒吧导航视图,只是表明你想要这取决于使用的方位之一)
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
1
首先阅读UIViewControllers是如何工作的: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
然后,在你的UIViewController子类,利用willRotateToInterfaceOrientation:duration:
优势,改变你的看法。
例如
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// if portrait
[self.landscapeView removeFromSuperview];
[self.view addSubview:self.portraitView];
// if landscape
[self.portraitView removeFromSuperview];
[self.view addSubview:self.landscapeView];
}
,并在适当if
陈述或switch
情况下添加,以确定哪些做。
相关问题
- 1. 当设备旋转时,使子视图也旋转iPhone/iPad
- 2. 当iPad/iPhone旋转时旋转子视图
- 3. iphone:在旋转可见视图时旋转翻转视图
- 4. 当iPad旋转时旋转视图
- 5. 当iPhone旋转时更改单元格中的背景图像
- 6. 旋转iPhone并改变视图
- 7. 当我旋转视图时,视图宽度不会改变
- 8. iPhone视图不会旋转
- 9. iPhone UITabBarController和旋转视图
- 10. iPhone:防止旋转视图
- 11. iphone - 处理视图旋转
- 12. 当iphone旋转时检测
- 13. 当旋转时更改UIImageview的边框
- 14. 当设备方向更改时,如何防止iPhone背景图像旋转?
- 15. 更改或禁用iPhone旋转动画时的方向更改
- 16. 更改设备旋转时的iPhone背景图像
- 17. 当Modal View Controller旋转时,iOS旋转视图控制器
- 18. iPhone旋转视频
- 19. 我需要一种方法,当父视图旋转时不旋转子视图
- 20. 更改视图iphone
- 21. 当在ios上旋转时改变子视图
- 22. iPhone:旋转绘图而不旋转绘制它的视图
- 23. 当屏幕旋转时,后退按钮更改为根视图控制器
- 24. UITabBar在旋转时更改所有视图
- 25. 当旋转屏幕时将列表转到图库视图?
- 26. iPhone:在UITableViewCell中旋转滚动视图
- 27. Iphone:旋转后重新加载视图
- 28. iPhone dev - 手动旋转视图
- 29. iPhone电影旋转只为子视图
- 30. 旋转superview iphone后移动子视图?
会在哪里我把代码注销了notifcations?在viewDidDisapear中? – Whyrusleeping
是或willdissapear。我忘了提及这种方法是为了当你得到一个复杂的布局,它有点难以管理,但它不应该干扰你平时的应用旋转行为。 – Pochi
我需要用来取消注册通知的唯一代码是[[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];'right? – Whyrusleeping