【发布时间】:2011-07-26 18:07:11
【问题描述】:
我有两个叠加图像,我想根据设备方向在相机视图中显示 - 一个用于水平方向,一个用于垂直方向(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");
}
}
【问题讨论】:
-
您想知道在 didOrientation 方法中如何将第一个图像视图更改为第二个图像视图?
标签: iphone orientation overlay uiimagepickercontroller