我在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
檢查攝像機視圖幀,並嘗試'bringsubviewToFront'如果需要 – visakh7 2011-05-09 05:38:29