监听iOS检测屏幕旋转状态,不需开启屏幕旋转
2014-02-27 14:26
162 查看
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>][self.view viewWithTagName:@"home_history"]; UIButton *cam_btn = [self.view viewWithTagName:@"cam_btn"]; UIButton *cut_btn = [self.view viewWithTagName:@"cut_btn"]; UIButton *light_btn=[self.view viewWithTagName:@"light_btn"]; history_btn.transform = CGAffineTransformMakeRotation(n*M_PI/180.0); cam_btn.transform = CGAffineTransformMakeRotation(n*M_PI/180.0); cut_btn.transform = CGAffineTransformMakeRotation(n*M_PI/180.0); light_btn.transform = CGAffineTransformMakeRotation(n*M_PI/180.0); } - (void)orientationChanged:(NSNotification *)note { UIDeviceOrientation o = [[UIDevice currentDevice] orientation]; switch (o) { case UIDeviceOrientationPortrait: // Device oriented vertically, home button on the bottom [self rotation_icon:0.0]; break; case UIDeviceOrientationPortraitUpsideDown: // Device oriented vertically, home button on the top [self rotation_icon:180.0]; break; case UIDeviceOrientationLandscapeLeft: // Device oriented horizontally, home button on the right [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; [self rotation_icon:90.0*3]; break; case UIDeviceOrientationLandscapeRight: // Device oriented horizontally, home button on the left [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; [self rotation_icon:90.0]; break; default: break; } } -(void)viewWillDisappear:(BOOL)animated { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; UIDevice *device = [UIDevice currentDevice]; //Get the device object [nc removeObserver:self name:UIDeviceOrientationDidChangeNotification object:device]; } - (void)viewDidAppear:(BOOL)animated { // Do any additional setup after loading the view from its nib. //----- SETUP DEVICE ORIENTATION CHANGE NOTIFICATION ----- UIDevice *device = [UIDevice currentDevice]; //Get the device object [device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app [nc addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:device];
相关文章推荐
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转-b
- IOS监听屏幕状态
- IOS UIDevice & IOS检测屏幕旋转实例
- iOS-OC-监听蓝牙是否开启(打开状态)
- iOS 判断当前屏幕旋转状态
- ios(ipad,iphone)屏幕旋转检测通用方法
- ios(ipad,iphone)屏幕旋转检测通用方法
- iOS 检测设备旋转状态
- IOS屏幕旋转的检测 与 强行切换
- iOS屏幕状态监听
- iOS监听屏幕旋转的几种方法
- iOS-检测监听网络状态(WIFI、2G/3G/4G)
- [IOS开发教程] IOS UIDevice & IOS检测屏幕旋转实例
- IOS UIDevice & IOS检测屏幕旋转实例
- iOS中检测当前设备的旋转方向(关闭屏幕旋转)
- ios 检测网络状态
- win7电脑开启屏幕旋转功能吗 Win7系统屏幕的旋转功能如何使用
- iOS 的Viewcontroller只支持一个屏幕方向,弹出不同方向,旋转
- iOS开发:关于屏幕旋转问题
- ios 开发之使用Reachability检测网络状态