iPhone開發應用中如何以消息通知方式設置旋轉View
iPhone開發應用中以消息通知方式設置旋轉View是本文要介紹的內容,主要是來學如何來旋轉View,具體內容來看本文詳解??吹竭@篇不錯, 直接轉載過來了, 沒什么可解釋的,一看就明白 :)。
整個程序需要支持橫豎屏切換得時候,會比較簡單,在每個ViewController 的
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中,return YES; 就好。
可如果只是要某個VC( = View Controller)支持橫豎屏切換呢?單獨在那個view controller中像上面那樣做是沒有效果的。
這個時候我們可以取 UIDevice的 Orientation來判定:
1、在VC中注冊 UIDevice 的 UIDeviceOrientationDidChangeNotification 通知:
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
- [center addObserver:self selector:@selector(doRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
2、在自己的 doRotate函數里面處理:
- - (void)doRotate:(NSNotification *)notification{
- UIDevice *myDevice = [UIDevice currentDevice];
- UIDeviceOrientation deviceOrientation = [myDevice orientation];
- UIApplication *app = [UIApplication sharedApplication];
- [app setStatusBarOrientation:deviceOrientation];
- }
3.
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
也是要 return YES。
小結:iPhone開發應用中以消息通知方式設置旋轉View的內容介紹完了,希望通過本文的學習能對你有所幫助!