I'm playing around with a cameraOverLayView and encountered a weird behavior. Before presenting the UIImagePickerController, I set allowsEditing to YES. After the capture screen comes up, I tap on a button that triggers takePicture(). Instead of presenting the editing screen, the delegate method didFinishPickingMediaWithInfo() gets called right away. Can anyone help me figure out what I could be doing wrong? I pasted some of my code below...
Thanks!
- (BOOL)shouldStartCameraController {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) {
return NO;
}
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float overlayOffset = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (screenSize.height > 480.0f) {
overlayOffset = 195;
} else {
overlayOffset = 103;
}
} else {
/*Do iPad stuff here.*/
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
&& [[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera] containsObject:(NSString *)kUTTypeImage]) {
cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceRear;
} else if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
} else {
return NO;
}
UIView *cameraOverlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height)];
UIImageView *cameraOverlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"iphone5_camera_overlay.png"]];
cameraOverlayImageView.frame = CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height);
[cameraOverlayView addSubview:cameraOverlayImageView];
UILabel *cameraLabel = [[UILabel alloc] initWithFrame:CGRectMake( 0.0f, self.view.bounds.size.height-overlayOffset, self.view.bounds.size.width, 50.0f)];
[cameraLabel setTextAlignment:NSTextAlignmentCenter];
[cameraLabel setBackgroundColor:[UIColor clearColor]];
[cameraLabel setTextColor:[UIColor whiteColor]];
[cameraLabel setShadowColor:[UIColor colorWithWhite:0.0f alpha:0.300f]];
[cameraLabel setShadowOffset:CGSizeMake( 0.0f, -1.0f)];
[cameraLabel setFont:[UIFont boldSystemFontOfSize:18.0f]];
[cameraOverlayView addSubview:cameraLabel];
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton addTarget:self action:#selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown];
[cancelButton setFrame:CGRectMake(10, cameraOverlayView.frame.size.height-60, 50, 50)];
[cancelButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:cancelButton];
UIButton *snapButton = [UIButton buttonWithType:UIButtonTypeCustom];
[snapButton addTarget:self action:#selector(takePictureButtonPressed:) forControlEvents:UIControlEventTouchDown];
[snapButton setFrame:CGRectMake(110, cameraOverlayView.frame.size.height-60, 100, 50)];
[snapButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:snapButton];
cameraUI.allowsEditing = YES;
cameraUI.showsCameraControls = NO;
cameraUI.delegate = self;
self.imagePickerController = cameraUI;
[self presentModalViewController:cameraUI animated:YES];
return YES;
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
[self shouldPresentPhotoCaptureController];
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
[self.imagePickerController takePicture];
}
Possible dublicate: How do I use [camera takePhoto] and edit using UIImagePicker - UIImagePickerController.allowsEditing = YES
According to takePicture: method in Apple documentation:
Use this method in conjunction with a custom overlay view to initiate the programmatic capture of a still image. This supports taking more than one picture without leaving the interface, but requires that you hide the default image picker controls.
Calling this method while an image is being captured has no effect. You must wait until the associated delegate object receives an imagePickerController:didFinishPickingMediaWithInfo: message before you can capture another picture.
It seems that this approach (custom overlay) it is configured in order to be managed by yourself. Even if "allowsEditing = YES" the taken picture will be directly sent to imagePickerController:didFinishPickingMediaWithInfo:.
Based on that if we want to edit the taken picture using our custom user interface we should create an according custom edit screen for that purpose.
Related
I have a question on UIImagePickerController. May I use UIImagePickerController as a preview? If I do like that, I have to hide record button, is there any way to do it? or Any other approach to show our preview other than UIImagePickerController.
thanks for your helps...
You can hide the controls of a UIImagePickerController by using:
[myImagePickerController setShowsCameraControls:NO];
EDIT: Check out this code, it hides all the controls inside the image picker allowing you to create and add your own custom controls. Unfortunately you can not selectively hide controls within the picker so this is the alternative.
- (void)showCamera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
myImagePicker = [[UIImagePickerController alloc] init];
[myImagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[myImagePicker setDelegate:self];
[myImagePicker setShowsCameraControls:NO];
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
UIButton *switchCameraButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[switchCameraButton setFrame:CGRectMake(10, 430, 72, 40)];
[switchCameraButton addTarget:self action:#selector(changeCamera:) forControlEvents:UIControlEventTouchUpInside];
[overlayView addSubview:switchCameraButton];
[myImagePicker setCameraOverlayView:overlayView];
[self presentViewController:myImagePicker animated:YES completion:nil];
}
}
- (IBAction)changeCamera:(id)sender
{
if (myImagePicker.cameraDevice == UIImagePickerControllerCameraDeviceFront) {
[myImagePicker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
}else{
[myImagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
}
I have a very strange problem when I'm testing my application on device. I have 2 views connected with Navigation Controller. My first view is very simple and has one UIButton. When clicking on this button happens switch to second view. My second view has UIButtons (>20) that are created programmatically. There is a problem, my switching animation work slower (than it should be) and with spurts. I tried to create same viewController with a lot of UIButtons but with Interface Builder and my animation is working correctly! This problem I have only when I'm testing application on real device, in simulator all of this variants work fine. Is there some difference in this two variants of creating UI elements? And how can I solve this problem with creating view with many of UI elements by programmatically (I prefer this way).
Edit1
I have a class whose superclass is UIButton. Here is implementation:
#import <QuartzCore/QuartzCore.h>
#import "UIHouseButtons.h"
#implementation UIHouseButtons
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *buttonImageNormal = [UIImage imageNamed:#"stateNormal.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[self setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"stateNormal.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[self setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[[self layer] setCornerRadius:4.0f];
[[self layer] setMasksToBounds:YES];
[self.titleLabel setFont:[UIFont fontWithName:#"Times New Roman" size:15.0f]];
self.frame = frame;
}
return self;
}
After in my second view controller in -loadView method:
UIHouseButtons *homeButton = [[UIHouseButtons alloc] initWithFrame:CGRectMake(435.0f, 5.0f, 40.0f, 25.0f)];
[homeButton setTitle:#"H" forState:UIControlStateNormal];
[self.view addSubview:homeButton];
and same 20 more times.
Edit 2 Edited my UIButtons class:
- (id)init
{
self = [super init];
if (self) {
self = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//self.backgroundColor = [UIColor clearColor];
UIImage *buttonImageNormal = [UIImage imageNamed:#"stateNormal.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[self setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"stateNormal.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[self setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[[self layer] setCornerRadius:4.0f];
[[self layer] setMasksToBounds:YES];
[self.titleLabel setFont:[UIFont fontWithName:#"Times New Roman" size:15.0f]];
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
}
return self;
}
My -viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
self.button1 = [[UIHouseButtons alloc] init];
self.button2 = [[UIHouseButtons alloc] init];
self.button3 = [[UIHouseButtons alloc] init];
self.button4 = [[UIHouseButtons alloc] init];
//and more 20 times
[self.view addSubview:self.button1];
[self.view addSubview:self.button2];
[self.view addSubview:self.button3];
[self.view addSubview:self.button4];
//and more 20 times
}
My viewWillAppear:
-(void)viewWillAppear:(BOOL)animated {
[self.button1 setFrame:CGRectMake(13.0f, 5.0f, 30.0f, 30.0f)];
[self.button2 setFrame:CGRectMake(57.0f, 5.0f, 30.0f, 30.0f)];
[self.button3 setFrame:CGRectMake(99.0f, 5.0f, 30.0f, 30.0f)];
[self.button4 setFrame:CGRectMake(141.0f, 5.0f, 30.0f, 30.0f)];
//and more 20 times
[super viewWillAppear:animated];
}
You have no problems with the speed in the Simulator, because the Simulator is a simulator of an iPhone/iPad, but not an emulator of the hardware of the iPhone/iPad and it uses your computer's CPU&RAM.
There shouldn't be any difference in the performance of creating controls as long as you respect some rules when doing it programmatically and these are:
If you aren't using a nib file, override the method -loadView and in there ONLY create a UIView and set it to self.view.
Then in -viewDidLoad method initialize you view hierarchy - you subviews of self.view, their subviews (buttons/labels/etc..). If you have hardcoded frame values you can set them here, but don't count on this, because in this method the view hierarchy geometry has not been setup correctly yet.
Then in -viewWillAppear:animated method adjust all geometry and perform only lightweight operations, because this method should return as fast as it can (otherwise you may face glitches when presenting)..
UPDATE:
From your code snippet update I can see your buttons' layers have rounded corners. This can become a performance issue especially if the buttons are in UIScrollView. Set all your buttons' layer to rasterize in UIHouseButtons.m file
self.layer.rasterizationScale = [[UIScreen mainScreen] scale]; //Add this if using images to adjust the proper rasterization scale for them.
self.layer.shouldRasterize = YES;
I was wondering which method is the easiest or "smartest" way of making a pause menu for games?
I don´t have that much experience with creating game pause menus so I´ve tried 2 methods that I came up with by my own. Both or in code beneath this text.
The first method I tried was to put a black almost transparent filter on top of the game, that I paused. I was successful with pausing everything except the touches made underneath the filter on my uiimages. I thought that putting a new uiimage on top of the current one would disable the touches made on the uiimages underneath it. I tried as well with touchenabled = NO but still nothing.
-(IBAction)pause{
NSLog(#"pause");
[countdowntimer invalidate];
[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];
[self.rubin3 stopAnimating];
Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;
//PauseMenu background
UIImage *image1 = [UIImage imageNamed: #"filter2.png"];
pausefilter = [[[UIImageView alloc] initWithImage:image1] autorelease];
CGRect newFrame1 = pausefilter.frame;
newFrame1 = CGRectMake(0,0, image1.size.width, image1.size.height);
pausefilter.frame = newFrame1;
[self.view addSubview:pausefilter];
[image1 release];
//Resume to Game
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(90, 146, 80, 18);
[button1 setImage:[UIImage imageNamed:#"RESUME.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:#selector(resume) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button1 ];
//End Game
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(260, 140, 180, 30);
[button2 setImage:[UIImage imageNamed:#"EndGame.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:#selector(end) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button2 ];
[sharedSoundManager pausePlayingMusic];
}
The second method I tried was to go back (switch view) to the options on the main menu to use the settings from there instead but I wasn´t able to resume back to where I paused the game. Instead the game restarted from the beginning.
-(IBAction)pause{
NSLog(#"pause");
[countdowntimer invalidate];
[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];
[self.rubin3 stopAnimating];
Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;
menureturn = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle: nil];
menureturn.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:menureturn animated: YES];
self.menureturn.Start.hidden = YES;
self.menureturn.option.hidden = YES;
self.menureturn.OptionsHeadtitle.hidden = NO;
self.menureturn.HowToPlayHeadtitle.hidden = YES;
self.menureturn.howtoplay.hidden = YES;
self.menureturn.filter.hidden = NO;
self.menureturn.music1.hidden = NO;
self.menureturn.music2.hidden = YES;
self.menureturn.SFXimage.hidden = NO;
self.menureturn.Musicimage.hidden = NO;
self.menureturn.sfx1.hidden = NO;
self.menureturn.sfx2.hidden = YES;
self.menureturn.credits.hidden = YES;
self.menureturn.back.hidden = YES;
self.menureturn.creditsinfo.hidden = YES;
self.menureturn.resume.hidden = NO;
self.menureturn.endgame.hidden = NO;
[sharedSoundManager pausePlayingMusic];
}
Is there a third option of how to make a god pause menu or just redo one of the two I already tried?
You can have a BOOL variable like
BOOL isGamePaused
Now when you are playing game i.e running not paused assign
isGamePaused = NO;
While you pause
isGamePaused = YES;
Now while playing animation or something like that you can use condition like
if(!isGamePaused) { ProceedAnimation;}
Hope this helps
The best thing to disable any event is to create a new element in your pause menu which will be the first responder and catches all events. So nothing can arrive to your game's interface ;)
HI all
can anyone please refer me, the iphone image gallery source code?
Any link ,sample code will be great help.
i am trying to show some 70 to 100 images as thumbnails , and on selecting any image, it should give a full view of that image,i am trying to accomplish, whatever is in iphone's picture gallery,
i thought, there must any sample code available.
suggestions are always appreciated
regards
In didload method call two methods to create scroll view and thumbnail button.Keep both thumbnail images and wallpaper images array in the same order.
-(void)createScrollView
{
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(320 * (([imagesArray count]- 1) / 25 + 1), 440);
scrollView.backgroundColor=[UIColor blackColor];
[self.view addSubview:scrollView];
}
-(void)createButton{
for (int i = 0; i < [imagesArray count]; i++)
{
thumbNailButton = [UIButton buttonWithType:UIButtonTypeCustom];
thumbNailButton.frame = CGRectMake(6 + 62 * (i % 5) + 320 * (i / 25), 5+65 * ((i / 5) % 5), 56,56);
img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 56, 56)];
[img setImage:[UIImage imageNamed:[imagesArray objectAtIndex:i]]];
thumbNailButton.tag=i;
[thumbNailButton addTarget:self action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[thumbNailButton addSubview:img];
[scrollView addSubview:thumbNailButton];
}
}
-(void)imageClicked:(id)sender{
UIButton* button = (UIButton*)sender;
AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate setimageClickedValue:button.tag];
LargeWallPaperviewController *largeWallPaperViewController=[[LargeWallPaperviewController alloc]initWithNibName:#"LargeWallPaperviewController" bundle:nil];
[self.navigationController pushViewController:largeWallPaperViewController animated:YES];
[largeWallPaperViewController release];
}
In largewallpaperviewcontroller class in didload method
[imagesArray addObjectsFromArray:[NSArray arrayWithObjects:#"wallf1.jpg",#"wallf2.jpg",#"wallf3.jpg",#"wallf4.jpg",#"wallf5.jpg",#"wallf6.jpg",#"wallf7.jpg",nil]];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 440)];
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(320 * ([imagesArray count] ), 440);
scrollView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scrollView];
for (int i = 0; i < [imagesArray count]; i++)
{
wallPaperButton=[UIButton buttonWithType:UIButtonTypeCustom];
wallPaperButton.tag=i;
wallPaperButton.frame=CGRectMake((320*i),0, 320, 325);
UIImageView *img =[ [UIImageView alloc]initWithFrame:CGRectMake(0,0, 320, 325)];
img.image=[UIImage imageNamed:[imagesArray objectAtIndex:i]];
img.contentMode=UIViewContentModeScaleAspectFit;
[wallPaperButton addSubview:img];
[img release];
[wallPaperButton addTarget:self action:#selector(imageSelected:) forControlEvents:UIControlEventTouchUpInside]; [scrollView addSubview:wallPaperButton];
}
appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
int imageValue=[appDelegate getimageClickedValue];
[scrollView scrollRectToVisible:CGRectMake(320*imageValue, 0, 320 , 440) animated:NO];
i have used a button in the largewallpaer view.If you want you remove it and directly add it to image view.This code is working for me ,change it to your requirement.Its easy to understand.
All the best.
Hats off to this code. This works perfectly. Although I have modified the "appdelegate part" since I was using story boards.
Here is what I did
-(void)imageClicked:(id)sender{
UIButton* button = (UIButton*)sender;
imageNumber = button.tag;
[self performSegueWithIdentifier:#"loadImage" sender:sender];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"loadImage"])
{
[segue.destinationViewController setimageValue:imageNumber];
}
}
And in my destination View Controller.m file named 'ImageViewController' I implemented things as below
-(void)setimageValue:(int)number;
{
self.imageValue = number;
}
And in viewDidLoad, instead of app delegate I just used
[self.scrollView scrollRectToVisible:CGRectMake(320*self.imageValue, 0, 320 , 440) animated:NO];
problem in adding second UIbutton in cameraOverlayView ,here i am able to add the first button but not able to add second button with following code
- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType {
[self reset];
// Create the Image Picker
if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
UIImagePickerController* aPicker =
[[[UIImagePickerController alloc] init] autorelease];
aPicker.sourceType = sourceType;
aPicker.delegate = self;
self.picker = aPicker;
// [[NSUserDefaults standardUserDefaults] boolForKey:#"allowEditing"];
BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera);
if ([picker respondsToSelector:#selector(setAllowsEditing:)]) {
// not in 3.0
[picker setAllowsEditing:!isCamera];
}
if (isCamera) {
if ([picker respondsToSelector:#selector(setShowsCameraControls:)]) {
[picker setShowsCameraControls:NO];
UIButton *cancelButton =
[UIButton buttonWithType:UIButtonTypeRoundedRect];
NSString *cancelString =
NSLocalizedString(#"DecoderViewController cancel button title", #"");
CGFloat height = [UIFont systemFontSize];
CGSize size =
[cancelString sizeWithFont:[UIFont systemFontOfSize:height]];
[cancelButton setTitle:cancelString forState:UIControlStateNormal];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"CancelButtonForButton.png"]];
//cancelButton.backgroundColor = [UIColor clearColor];
//cancelButton.backgroundColor = [UIColor greenColor];
[cancelButton setImage:[UIImage imageNamed:#"cancelForButton.png"] forState:UIControlStateNormal];
//[cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
CGRect appFrame = [[UIScreen mainScreen] bounds];
static const int kMargin = 10;
static const int kInternalXMargin = 10;
static const int kInternalYMargin = 10;
CGRect frame = CGRectMake(kMargin,
appFrame.size.height - (height + 2*kInternalYMargin + kMargin),
2*kInternalXMargin + size.width,
height + 2*kInternalYMargin);
[cancelButton setFrame:frame];
[cancelButton addTarget:self
action:#selector(cancel:)
forControlEvents:UIControlEventTouchUpInside];
picker.cameraOverlayView = cancelButton;
// The camera takes quite a while to start up. Hence the 2 second delay.
[self performSelector:#selector(takeScreenshot)
withObject:nil
afterDelay:2.0];
//cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
}
}
// Picker is displayed asynchronously.
[self presentModalViewController:picker animated:YES];
} else {
NSLog(#"Attempted to pick an image with illegal source type '%d'", sourceType);
}
}
The issue is that you are replacing the camera overlay with the first button - so creating the second button and using "picker.cameraOverlayView = newButton;" replaces the camera-overlay again.
The solution is to create a parent UIView, add both buttons to it, and then set the camera overlay to be the parent UIView.