Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 检测UIImagePickerController中的方向变化?_Iphone_Objective C_Camera_Uipickerviewcontroller - Fatal编程技术网

Iphone 检测UIImagePickerController中的方向变化?

Iphone 检测UIImagePickerController中的方向变化?,iphone,objective-c,camera,uipickerviewcontroller,Iphone,Objective C,Camera,Uipickerviewcontroller,我试图检测UIImagePickerController中的方向变化(它继承自UIAvigationController:UIViewController:UIResponder:NSObject),并尝试覆盖UIViewController中的方法-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation,但没有成功 有什么建议吗 提前感谢…来自UIImagePickerCo

我试图检测UIImagePickerController中的方向变化(它继承自UIAvigationController:UIViewController:UIResponder:NSObject),并尝试覆盖UIViewController中的方法
-(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
,但没有成功

有什么建议吗


提前感谢…

来自UIImagePickerController官方文档:

重要提示:UIImagePickerController类仅支持纵向模式。此类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改,只有一个例外。在iPhone OS 3.1及更高版本中,可以将自定义视图指定给cameraOverlayView属性,并使用该视图显示其他信息或管理摄像头界面与代码之间的交互


不支持子类化UIImagePickerController

此类旨在按原样使用,不支持子类化


也许你可以注册并使用这个?

现在回答这个问题太晚了,但我正在扩展@Adam Wośanswer

在演示UIImagePickerController之前

UIImagePickerController *controllerObject = [[UIImagePickerController alloc] init];
...
...
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)name:UIDeviceOrientationDidChangeNotification  object:nil];
...
...
[self presentViewController:controllerObject animated:YES completion:nil];

- (void)orientationChanged:(NSNotification *)notification{
    [self adjustViewsForOrientation:UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
{
    if(orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
    {
        NSLog(@".....landscape.....");
    }
    else if(orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)
    {
        NSLog(@".....portrait.....");
    }
}
UIImagePickerController
退出时,不要忘记

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
另请注意,根据@FelixLam对@Adam Wośanswer的评论

如果设备方向被锁定,则不再发布通知

要处理这种情况,需要实施
CoreMotion
(可选
uiaccelerator
iOS<6.0)来检测设备方向是否锁定。这是
UIAccelerator
的博客,这是
CoreMotion
的博客,你需要一些逻辑来检查这一点


祝你好运

请注意,设备方向更改包含的常量比接口方向(即:面朝上和面朝下)多两个–您必须记住上一个方向(纵向/横向)并忽略正面向上/向下的更改,以了解您实际处于哪个界面方向。不幸的是,如果设备的方向被锁定,则不会再发布通知,但相机界面仍在更新。您是否找到了解决方法?另一个问题是设备方向不一定与摄像头方向匹配。