我有两个重叠的图像,我希望根据设备方向在相机视图中显示其中一个 - 一个用于纵向方向,一个用于横向方向(overlay_v.png和overlay_h.png)。当设备从纵向旋转到纵向方向时,覆盖图像也应更改。
使用beginGeneratingDeviceOrientationNotifications,我只能确定设备方向,但无法成功更改覆盖图像。如有疑问或不同的方法,请不吝赐教。
- (IBAction) getPhoto:(id) sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
sourceCamera = false;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
} else {
sourceCamera = true;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//overlay image (cannot dynamically switch from vertical to horizontal in here)
UIImageView *anImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"overlay_v.png"]];
anImageView.frame = CGRectMake(0, 0, anImageView.image.size.width, anImageView.image.size.height);
picker.cameraOverlayView = anImageView;
//device orientation check
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didOrientation:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
[anImageView release];
}
[self presentModalViewController:picker animated:YES];
}
- (void) didOrientation: (id)object {
UIInterfaceOrientation interfaceOrientation = [[object object] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"portrait");
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft ){
NSLog(@"landscape");
}
}