通过以下代码完成:
//判断软件方向
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];/*添加通知之前需要先执行这一句*/
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(deviceOrientationChnaged) name:UIDeviceOrientationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self];
[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];/*最后这句也要加上*/