【问题标题】:Problems in iPhone camera overelay image orientationiPhone相机覆盖图像方向的问题
【发布时间】:2011-10-14 05:07:28
【问题描述】:
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(dragger.frame.origin.x, dragger.frame.origin.y,dragger.frame.size.width, dragger.frame.size.height)] ;
imgView.image = dragger.image;  
overlayView = [[UIView alloc] initWithFrame:CGRectMake(dragger.frame.origin.x,dragger.frame.origin.y,dragger.frame.size.width, dragger.frame.size.height)];
[overlayView addSubview:imgView];

//open the camera

self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraOverlayView=overlayView;  
[self.navigationController presentModalViewController:self.picker animated:YES];

这在纵向模式下可以正常工作,但在横向模式下叠加图像不会改变。

如果我需要帮助,我该如何实现?

【问题讨论】:

标签: iphone orientation uiimagepickercontroller


【解决方案1】:

您需要注册以更改方向...像这样

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:@"UIDeviceOrientationDidChangeNotification" 
                                               object:nil];

然后在同一个类中写这个函数......

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

    //do stuff

    if (orientation==UIDeviceOrientationPortrait) {
        imagePickerController.cameraOverlayView = portraitImageView;

    }

    else if(orientation==UIDeviceOrientationLandscapeLeft)
    {

        imagePickerController.cameraOverlayView = landscapeImageView;

    }

}

【讨论】:

  • 感谢您的回答。但是图像是动态的(dragger.image)。那么我应该为 PortraitImageView 和 LandscapeImageView 提供什么?
  • 你应该用你的 dragger.image 初始化这些图像视图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-08
  • 2012-01-30
  • 2010-11-03
  • 1970-01-01
  • 2011-12-25
  • 1970-01-01
相关资源
最近更新 更多