UIImagePickerControllerSourceTypeCamera 被父视图对象覆盖

发布于 2024-11-06 00:50:56 字数 6714 浏览 0 评论 0原文

我正在 XCode 4 中创建一个基于窗口的应用程序(我使用基于窗口的应用程序是因为我喜欢通用应用程序的组织方式),但我在使用 UIImagePickerControllerSourceTypeSavedPhotosAlbum 时遇到了问题。我尝试尽可能地精简代码以避免任何外部错误,但我想要有两个视图:

父视图: Threeeyesmain.h / m / xib 子

视图: Threeeyescamera.h / m / xib

我将发布到目前为止我的代码如下。

主要问题是,当我按下按钮用相机拍照时,它可以工作,我可以看到相机控件,我什至可以毫无问题地拍照。但是,父视图中的任何对象都会覆盖相机屏幕。 (即,如果我将相机指向花朵的图片,我可以在屏幕上看到花朵,但父视图上覆盖有按钮和图像视图。我希望​​这是有道理的)。

(旁注:有趣的是,当我在使用基于视图的应用程序之前尝试此操作时,它似乎有效,但现在在基于 Windows 的应用程序中使用几乎相同的代码,我遇到了这些问题。)

也许我只是错过了一些东西真的很明显。任何帮助将不胜感激。谢谢!

trieyesmain.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

trieyesmain.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

trieyescamera.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

trieyescamera.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

I am creating a window-based application in XCode 4 (I am using window-based because I like how the universal apps are organized), but I am having trouble with the UIImagePickerControllerSourceTypeSavedPhotosAlbum. I tried stripping down the code as much as possible to avoid any external errors, but I want to have two views:

the parent view: threeeyesmain.h / m / xib

the sub view: threeeyescamera.h / m / xib

I will post the code I have so far below.

The main issue is, when I push the button to take a picture with the camera, it works and I can see the camera controls, and I can even take a picture with no problem. However, whatever objects that are in the parent view are covering the camera screen. (i.e. if I am pointing my camera over a picture of a flower, I can see the flower on the screen, but there are buttons and imageviews from the parent view overlayed on it. I hope that makes sense).

(Side note: The funny thing is, when I tried this before using a view based application, it seemed to work, but now using virtually the same code in a windows based application, I get these problems.)

Maybe I am just missing something really obvious. Any help would greatly be appreciated. Thanks!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作死小能手 2024-11-13 00:50:56
[self.view bringSubviewToFront:viewname];
[self.view bringSubviewToFront:viewname];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文