简体   繁体   English

UIImagePickerControllerSourceTypeCamera被父视图对象覆盖

[英]UIImagePickerControllerSourceTypeCamera is covered by parent view objects

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. 我正在XCode 4中创建一个基于窗口的应用程序(我使用基于窗口的应用程序是因为我喜欢通用应用程序的组织方式),但是我在使用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 父视图:threeeyesmain.h / m / xib

the sub view: threeeyescamera.h / m / xib 子视图: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. 但是,父视图中的任何对象都将覆盖相机屏幕。 (ie 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.) (附带说明:有趣的是,当我在使用基于视图的应用程序之前尝试过这种方法时,它似乎可以工作,但是现在在基于Windows的应用程序中使用几乎相同的代码,我遇到了这些问题。)

Maybe I am just missing something really obvious. 也许我只是缺少一些明显的东西。 Any help would greatly be appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

threeeyesmain.h 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 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 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用UIImagePickerControllerSourceTypeCamera查看UIImagePickerController的移位问题,数据源为 - View shift problem with UIImagePickerController with datasource as UIImagePickerControllerSourceTypeCamera UIButton 被视图覆盖(或半覆盖)时禁用 - UIButton disabled when covered (or semi covered) by a view UITableView被自定义日历视图覆盖 - UITableView Being Covered by Custom Calendar View UIImagePickerControllerSourceTypeCamera占用内存 - UIImagePickerControllerSourceTypeCamera hogging up memory UIImagePickerControllerSourceTypeCamera 导航问题 - UIImagePickerControllerSourceTypeCamera problem with Navigation UIImagePickerControllerSourceSourceCamera在IPHONE模拟器中崩溃? - UIImagePickerControllerSourceTypeCamera crashes in IPHONE Simulator? UIImagePickerControllerSourceTypeCamera的自定义showCameraControls - Custom showsCameraControls for UIImagePickerControllerSourceTypeCamera 为 UIImagePickerControllerSourceTypeCamera 获取 SIGABRT - getting SIGABRT for UIImagePickerControllerSourceTypeCamera 在UIImagePickerControllerSourceTypeCamera之后立即调整图像大小 - Immediately Resize Image after UIImagePickerControllerSourceTypeCamera 模态UIViewController覆盖视图时取消UITouch事件 - Cancel UITouch Events When View Covered By Modal UIViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM