您的位置:首页 > 移动开发 > IOS开发

iOS监听设备方向的方法

2016-06-05 20:54 429 查看
1.添加监听函数 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
        [[NSNotificationCenter defaultCenter] addObserver:self 
         
                                                 selector:@selector(deviceOrientationDidChange:) 
         
                                                     name:UIDeviceOrientationDidChangeNotification 
         
                                                   object:nil]; 
2.得到设备对象 
  -(void)deviceOrientationDidChange:(NSObject*)sender{ 
    UIDevice* device = [sender valueForKey:@"object"]; 
    NSLog(@"%d",device.orientation); 
    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: