[英]View shift problem with UIImagePickerController with datasource as UIImagePickerControllerSourceTypeCamera
[英]UIImagePickerControllerSourceTypeCamera is covered by parent view objects
我正在XCode 4中創建一個基於窗口的應用程序(我使用基於窗口的應用程序是因為我喜歡通用應用程序的組織方式),但是我在使用UIImagePickerControllerSourceTypeSavedPhotosAlbum時遇到了麻煩。 我嘗試盡可能地減少代碼以避免任何外部錯誤,但是我想擁有兩個視圖:
父視圖:threeeyesmain.h / m / xib
子視圖: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
三眼相機
#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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.