Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-08-2011, 10:46 PM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
jamesjmadison is on a distinguished road
Default NEED HELP! UIImagePickerControllerSourceTypeCamera covered by parent view objects

Hello,

I am creating a window-based xcode 4 project (I am using window-based application 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

Code:
#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

Code:
#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

Code:
#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

Code:
#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

Last edited by jamesjmadison; 05-09-2011 at 12:29 AM.
jamesjmadison is offline   Reply With Quote
Reply

Bookmarks

Tags
camera, ipad, iphone, uiimagepickercontroller, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 351
9 members and 342 guests
dansparrow, iOS.Lover, lorrettaui53, MikaelBartlett, oztemel, pbart, PlutoPrime, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0