检测 UIImagePickerController 中的方向变化?

发布于 2024-08-17 22:02:03 字数 291 浏览 9 评论 0 原文

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

有什么建议吗

提前致谢...

Im trying to detect orientation changes in a UIImagePickerController (it inherits from UINavigationController : UIViewController : UIResponder : NSObject) and I tried override the method - (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation in UIViewController but no success...

any tips?

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

折戟 2024-08-24 22:02:03

不支持子类化 UIImagePickerController!

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

也许您可以注册 UIDevice 的“nofollow noreferrer”>UIDeviceOrientationDidChangeNotification 并使用它?

Subclassing UIImagePickerController is not supported!

This class is intended to be used as-is and does not support subclassing.

Maybe you could register for UIDeviceOrientationDidChangeNotification from UIDevice and use this?

浸婚纱 2024-08-24 22:02:03

现在在这里回答已经太晚了,但我正在扩展@Adam Woś的答案,

在呈现 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ś 答案的评论,

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

为了处理这种情况,需要实现 CoreMotion(替代的 UIAccelerometer iOS <6.0)来检测设备方向是否被锁定。这是 UIAccelerometer http://blog.sallarp. 的博客。 com/iphone-accelerometer-device-orientation/ 这是用于 CoreMotion https ://github.com/tastyone/MotionOrientation 您必须使用一些逻辑来检查这一点。

祝你好运!

This is too late to answer here, but I'm expanding @Adam Woś answer,

Before presenting 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.....");
    }
}

When UIImagePickerController get dismiss don't forget,

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

Also note that, as per @FelixLam comment on @Adam Woś answer,

if device orientation is locked then notifications no longer posted.

To handle this situation, one need to implement CoreMotion (alternative UIAccelerometer iOS < 6.0) to detect that device orientation is locked or not. Here's the blog for UIAccelerometer http://blog.sallarp.com/iphone-accelerometer-device-orientation/ and this is for CoreMotion https://github.com/tastyone/MotionOrientation You'll have to kick some logic to check this.

Good luck!

陌上芳菲 2024-08-24 22:02:03

来自官方 UIImagePickerController 文档:

重要提示: UIImagePickerController 类仅支持纵向模式。该类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改,但有一个例外。在iPhone OS 3.1及更高版本中,您可以将自定义视图分配给cameraOverlayView属性,并使用该视图来呈现附加信息或管理相机界面与代码之间的交互。

From the official UIImagePickerController documentation:

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. In iPhone OS 3.1 and later, you can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文