我正在开发支持2个方向的iPhone应用程序。我有2视图控制器的UIView文件。我需要根据设备接口方向将相应的UIView文件设置到视图控制器。你能指导我如何改变方向吗?如何在iPhone中更改方向时更改视图控制器的视图?
0
A
回答
3
为什么要为两个方向使用两个视图?您可以设置控件的autoresizemask属性,如果纵向和横向两种模式都具有类似的控件以显示在相同的位置。否则,您需要在
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
使用两个视图,或者你可以拥有的UIDevice
的通知UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;
- (void)beginGeneratingDeviceOrientationNotifications; // nestable
- (void)endGeneratingDeviceOrientationNotifications;
2
只需在您的控制器中为这两个方向分配代表。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
3
假设你已经设置-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
来回报您的支持方向,你可以使用都可以在UIViewController设置检查方向更改下面的方法,然后设置你的观点:
// called just before the user interface starts to rotate - my advice would be to use this method to save a copy of the current orientation.
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
// called after the interface has finished rotating. Here, you can compare the old orientation with the new one - if you went from portrait to landscape, then update your views accordingly.
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
希望这有助于!
相关问题
- 1. iphone如何更改视图控制器
- 2. 当设备方向改变时更改视图控制器
- 3. 更改iPhone中视图的方向
- 4. iOS:在弹出视图控制器时更改界面方向
- 5. 视图控制器之间在方向更改时导航
- 6. 如何在控制器中更改ViewModel时更新视图
- 7. 如何更改特定视图的视图控制器的方向
- 8. 缩放iPhone的方向更改视图
- 9. 容器视图控制器中的力方向更改
- 10. iPhone视图uiorientation不工作后更改视图控制器
- 11. 如何更改容器视图(嵌入式视图控制器)中的视图?
- 12. 如何更改方向更改时的视图布局?
- 13. 更改视图iphone
- 14. 如何更改根视图控制器在iphone中查看控制器
- 15. 如何在导航弹出视图控制器时更改动画的方向
- 16. 分段控制改变时更改视图控制器
- 17. 更改UITabBarController的视图控制器
- 18. 更改角度视图的控制器
- 19. 从控制器更改视图不触发视图更新
- 20. iPhone - 更改导航控制器的视图,使用子视图中的按钮
- 21. UItabBar更改视图控制器
- 22. MGSplitViewController更改详细视图控制器
- 23. 更改视图控制器 - SIGABRT
- 24. 更改视图控制器Swift 3
- 25. 更改子视图控制器
- 26. Xcode 6更改视图控制器
- 27. 更改后视图控制器iOS4.3
- 28. 视图控制器层级和设备方向更改
- 29. 在两个视图控制器之间更改UIImage视图
- 30. 以编程方式在子视图的控制器中更改子视图