UIImagePickerControllerSourceTypeCamera被父视图对象覆盖
我在XCode 4中创建基于窗口的应用程序(因为我喜欢通用应用程序的组织方式,所以我使用基于窗口的应用程序),但是我遇到了UIImagePickerControllerSourceTypeSavedPhotosAlbum问题。我试图剥离下来的代码,尽可能避免任何外部错误,但我想有两种观点:UIImagePickerControllerSourceTypeCamera被父视图对象覆盖
父视图:threeeyesmain.h/M /厦门国际银行
副视点:threeeyescamera.h/m/xib
我会发布我到目前为止下面的代码。
主要问题是,当我按下按钮以使用相机拍摄照片时,它可以正常工作,我可以看到照相机控制,甚至可以拍摄没有问题的照片。但是,父视图中的任何对象都会覆盖相机屏幕。 (也就是说,如果我将相机对准花朵图片,我可以在屏幕上看到花朵,但是从父视图中叠加了按钮和图像视图,我希望这是有道理的)。 (注意:有趣的是,当我在使用基于视图的应用程序之前尝试这个功能时,它似乎可以正常工作,但是现在在基于Windows的应用程序中使用几乎相同的代码,我得到了这些问题。)
也许我只是错过了一些非常明显的东西。任何帮助将不胜感激。谢谢!
threeeyesmain.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <MediaPlayer/MediaPlayer.h>
@interface threeeyesmain : UIViewController {
}
-(IBAction)switchtothreeeyescamera:(id)sender;
-(IBAction)back:(id)sender;
@end
threeeyesmain.m
#import "threeeyesmain.h"
#import <AVFoundation/AVAudioPlayer.h>
#import <MediaPlayer/MediaPlayer.h>
#import "threeeyescamera.h"
@implementation threeeyesmain
-(IBAction)switchtothreeeyescamera:(id)sender{
threeeyescamera *mythreeeyescamera = [[threeeyescamera alloc]
initWithNibName:@"threeeyescamera"
bundle:nil];
UIView *thecurrentView = nil;
thecurrentView = self.view;
UIView *thenextView = nil;
thenextView = mythreeeyescamera.view;
thenextView.alpha = 0.0;
[self.view addSubview:thenextView];
[UIView beginAnimations:@"fadeview" context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:thenextView];
thenextView.alpha = 1.0;
[UIView commitAnimations];
}
-(IBAction)back:(id)sender {
[UIView beginAnimations:@"flipview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
threeeyescamera.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface threeeyescamera : UIViewController {
UIImageView *SetPhotoImageView;
UIImagePickerController *imgPicker;
UIButton *BackButton;
}
@property (nonatomic, retain) IBOutlet UIImageView *SetPhotoImageView;
@property (nonatomic, retain) IBOutlet UIImagePickerController *imgPicker;
@property (nonatomic, retain) IBOutlet UIButton *BackButton;
-(IBAction)setImage:(id)sender;
-(IBAction)back:(id)sender;
@end
threeeyescamera.m
#import "threeeyescamera.h"
@implementation threeeyescamera
@synthesize imgPicker, SetPhotoImageView, BackButton;
-(IBAction)setImage:(id)sender{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
// if((UIButton *) sender == ChoosePhoto) {
// picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// } else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// }
[self presentModalViewController:picker animated:YES];
}
-(IBAction)back:(id)sender {
[UIView beginAnimations:@"fadeview" context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
UIView *theView = nil;
theView = self.view;
[UIView setAnimationDelegate:theView];
theView.alpha = 0.0;
[UIView commitAnimations];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
SetPhotoImageView.image = img;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSData *ImageData = UIImageJPEGRepresentation(img, 0.9);
[prefs setObject:ImageData forKey:@"ImageSpaceMiddle"];
[prefs synchronize];
SetPhotoImageView.image = [UIImage imageWithData:ImageData];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([prefs objectForKey:@"ImageSpaceMiddle"]) {
NSData *imgData = [prefs objectForKey:@"ImageSpaceMiddle"];
SetPhotoImageView.image = [UIImage imageWithData: imgData];
}
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
[self.view bringSubviewToFront:viewname];
感谢您的答复家伙! 我将此添加到threeeyescamera.m,但我认为我做错了什么。 - (IBAction为)SetImage:(ID)发送方{ \t \t \t的UIImagePickerController *挑选器= [[ALLOC的UIImagePickerController] INIT]; \t picker.delegate = self; \t \t 如果((的UIButton *)发送方== ChoosePhoto){ \t \t picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; \t} else { \t \t picker.sourceType = UIImagePickerControllerSourceTypeCamera; \t} \t \t [self presentModalViewController:picker animated:YES]; [self。查看bringSubviewToFront:picker.view]; \t } 我认为需要更多的手持〜 – user744349 2011-05-11 23:15:20
我也意识到我添加了ImagePickerController作为模态视图。另外,当我使用UIImagePickerControllerSourceTypeSavedPhotosAlmum时,它显示正常。这只是被掩盖的UIImagePickerControllerSourceTypeCamera。 – user744349 2011-05-11 23:37:10
检查摄像机视图帧,并尝试'bringsubviewToFront'如果需要 – visakh7 2011-05-09 05:38:29