开发者

Problems in iPhone camera overelay image orientation

开发者 https://www.devze.com 2023-04-12 18:38 出处:网络
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(dragger.frame.origin.x, dragger.frame.origin.y,dragger.frame.size.width, dra开发者_如何学Gogger.frame.size.height)] ;
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(dragger.frame.origin.x, dragger.frame.origin.y,dragger.frame.size.width, dra开发者_如何学Gogger.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];

This works fine in portrait mode but the overlay image does not change while in the landscape mode.

How can i achieve this as I need help on this?


you need to register for change in orientation... like this

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

and then write this function in the same class....

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

    //do stuff

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

    }

    else if(orientation==UIDeviceOrientationLandscapeLeft)
    {

        imagePickerController.cameraOverlayView = landscapeImageView;

    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号