iPhone相机覆盖图像方向的问题

时间:2011-10-14 05:07:29

标签: iphone orientation uiimagepickercontroller

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];

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

如果我需要帮助,我怎样才能实现这一目标?

1 个答案:

答案 0 :(得分:0)

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

[[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;

    }

}