1. 程式人生 > >iOS監聽裝置方向的方法

iOS監聽裝置方向的方法

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); 

}