加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – UIImagePickerController(使用相机作为源代码)在

发布时间:2020-12-16 07:25:07 所属栏目:百科 来源:网络整理
导读:我正在尝试使用一些相机功能编写应用程序,并使用叠加视图来装饰图像. 这是我实现应用程序的方式: 我使用UIImagePickerController来向用户提供相机所使用的内容,并将UIImageView作为子视图添加到cameraOverlayView上,以便它像这样工作: (图片在http://www.m
我正在尝试使用一些相机功能编写应用程序,并使用叠加视图来装饰图像.

这是我实现应用程序的方式:
我使用UIImagePickerController来向用户提供相机所使用的内容,并将UIImageView作为子视图添加到cameraOverlayView上,以便它像这样工作:
(图片在http://www.manna-soft.com/test/uploads/UIImagePickerView-portrait.jpg)

这种方法很好,直到iPad2到位……它会像这样自动旋转并破坏布局:
(图片于http://www.manna-soft.com/test/uploads/UIImagePickerView-landscape.jpg)

UIImagePickerController永远不会在iphone,ipod touch或原始iPad上旋转,但它在iPad2上运行.
UIImagePickerContrller的类引用说它“仅支持肖像模式”,但是会发生什么呢?它会像那样自动旋转….
有没有办法可以禁用自动旋转?
我尝试在UIImagePickerController呈现的视图控制器的方法shouldAutorotateToInterfaceOrientation中返回NO,但它仍然会旋转.

提前致谢.

解决方法

您可以通过掠夺UIImagePickerController的叠加视图来补偿ipad的旋转. Fisrt你必须使用以下方法捕获通知:

[[NSNotificationCenter defaultCenter]     addObserver:self selector:@selector(notificationCallback:) name:nil object:nil];

然后使用此代码:

- (void) notificationCallback:(NSNotification *) notification {
  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if ([[notification name] isEqualToString:@"UIDeviceOrientationDidChangeNotification"]) { 

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

        switch ( orientation ) {
            case UIInterfaceOrientationLandscapeRight:
                NSLog(@"LandcapeRight");
                [UIView beginAnimations:@"LandscapeRight" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformIdentity;
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationLandscapeLeft:
                NSLog(@"LandscapeLeft");
                [UIView beginAnimations:@"LandcapeLeft" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI),0);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                NSLog(@"UpsideDown");
                [UIView beginAnimations:@"UpsideDown" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(-M_PI / 2),-128,-128);
                [UIView commitAnimations];
                break;
            case UIInterfaceOrientationPortrait:
                NSLog(@"Portrait");
                [UIView beginAnimations:@"Portrait" context:UIGraphicsGetCurrentContext()];
                [UIView setAnimationDuration:0.4];
                m_uiCameraOverlayView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(M_PI / 2),128,128);
                [UIView commitAnimations];
                break;
            default:
                NSLog(@"????");
                break;
        }
    }
 }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读