How to set the Camera screen size in Retina 4? - camera

I've made the simple camera app in iPhone. In iPhone 4, it works well with the proper camera screen size, but in iPhone5 it appear the black bar between the camera screen and the bottom bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:#"tick"
ofType:#"aiff"]],
&_tickSound);
self.imgPickController = [[[UIImagePickerController alloc] init] autorelease];
self.imgPickController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imgPickController.delegate = self;
self.imgPickController.showsCameraControls = NO;
posCaptDevice = UIImagePickerControllerCameraDeviceRear;
nCountSec = 0;
self.view.frame = [UIScreen mainScreen].bounds;
[self initCamera];
}
return self;
}

is your app iPhone 5 optimised?.It could be a reason. if your app is not iPhone 5 optimised,
This will help to do it
anyway you will have to do it. Now apps are not allowed to submit without iPhone 5 support .

Related

UITextFieldDelegate works on iOS 8 but not iOS 7

I have a UIViewController that has a UITextField in it, and conforms to the UITextFieldDelegate protocol. When I first built the app iOS 7 was the latest iOS and when I selected the text field, the keypad would appear, as expected.
Along comes iOS 8 and Xcode 6. Nothing changed in the code since I first wrote it, but now, curiously, when I select the text field on an iOS 8 device the keypad appears, but on an iOS 7 device it does not.
Why would this be? Any ideas?
Here is my code:
#import "BBFeatVC.h"
#interface BBFeatVC ()
#end
#implementation BBFeatVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.featTextField.delegate = self;
// Set label
self.featLabel.numberOfLines = 0;
// enhance keypad
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancelNumberPad)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:#"Apply" style:UIBarButtonItemStyleDone target:self action:#selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
self.featTextField.inputAccessoryView = numberToolbar;
}
-(void)cancelNumberPad{
[self.featTextField resignFirstResponder];
}
-(void)doneWithNumberPad{
NSString *numberFromTheKeyboard = self.featTextField.text;
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *num = [f numberFromString:numberFromTheKeyboard];
NSInteger newStat = [num integerValue];
[[NSUserDefaults standardUserDefaults] setInteger:newStat forKey:self.featStat];
[self.featTextField resignFirstResponder];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
A red herring if there ever was one. As it turns out this was a case of the iOS Simulator detecting the hardware keyboard and therefore not raising the simulated iPhone keypad. The reason I thought the delegate was working on iOS 8 and not iOS 7 is because my device runs iOS 8 and so I would test on the device when I tested that version of iOS, and I used the simulator when I needed to test iOS 7. Once I tested iOS 8 on the simulator I discovered my flawed assumption and it dawned on me the difference was not between iOS versions but between device and simulator. I corrected the problem by going into the Simulator, and then in the Hardware Menu, then Keyboard, then uncheck the "Connect Hardware Keyboard" option.
This frustrated me to no end. I hope someone benefits from my posting!

UIImagePickerController camera freezes when flip and cancel a few times

Hello I'm working in an app with camera.
I can open and use the camera correctly. But I find a bug:
When I open the camera, flips camera, again flips camera and press cancel. Do it a few times ( 3 - 5 ) . Open again the camera and I have a black freeze screen for a few seconds and if you take a picture see the image but the screen continue in black. After a few seconds the camera appears again and you can continue with the normal behavior. But I cant find a solution to this.
I searched a lot in internet and find some answers but nothing solve my problem.
Here a similar problem but the solution didnt work for me:
Stackoverflow - UIImagePickerController Freezes when camera flips
Stackoverflow - UIImagePicker freezes
Stackoverflow - iOS 7 UIImagePicker preview black screen
Stackoverflow - iDevice camera shows black instead of preview
Also I use DejalBezelActivityView to create a spinner area with a label DejalBezelActivityView
Any idea?
I have my .h declaration:
#property (nonatomic, strong) UIImagePickerController* picker;
- (void) takePhoto: (id)vc;
- (void) selectPhoto: (id)vc;
And my .mm code:
#synthesize picker = _picker;
- (id) init{
self = [super init];
if (self){
self.picker = [[UIImagePickerController alloc] init];
}
return self;
}
- (void)takePhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[VC_Camera showAlert];
return;
}
[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}
- (void)selectPhoto:(id)vc{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
[VC_Camera showAlert];
return;
}
[self init];
self.picker.delegate = self;
self.picker.allowsEditing = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[[VC_Camera getMainWindow] presentViewController:self.picker animated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
self.picker = picker;
DejalActivityView * _activityView = [DejalBezelActivityView activityViewForView:[[UIApplication sharedApplication] keyWindow] withLabel:#"Loading"];
[self performSelector:#selector(cancelAfterDelay:) withObject:#{#"DejalAV":_activityView} afterDelay:1.0];
}
- (void) cancelAfterDelay:(NSDictionary*) dict
{
DejalActivityView* _activityView = [dict objectForKey:#"DejalAV"];
[DejalBezelActivityView removeViewAnimated:YES];
[self.picker dismissViewControllerAnimated:YES completion:nil];
}
Thanks :D
[UPDATE]
I try to use the UIImagePickerController as a singleton:
-(UIImagePickerController *) imagePicker{
if(!_imagePicker){
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
_imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
}
}
return _imagePicker;
}
And the problem persist.
This is a very late response, but for those still wrestling with this issue: I've noticed this seems to happen when something is either backing up the main thread, or affecting the graphics context on a separate thread. Those might be places to start looking.

UIView with rotation issues

I've a sample project, where I'm creating an custom UIViewController.
#import "ViewController.h"
#implementation ViewController
#synthesize webViews = _webViews;
#synthesize webView = _webView;
- (void)setWebView:(UIWebView *)webView {
if (webView!=_webView) {
[self.webView removeFromSuperview];
_webView = nil;
_webView = webView;
[self.view addSubview:self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com/"]]];
}
}
- (IBAction)newWebView:(id)sender {
self.webView = [self.webViews objectAtIndex:1];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIWebView *webView1 = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIWebView *webView2 = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.webViews = [NSArray arrayWithObjects: webView1, webView2, nil];
self.webView = [self.webViews objectAtIndex:0];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end
Two UIWebView's are created inside the viewWillAppear:animated and stored in an array -- and than the first UIWebView is added to the subview of self.view. When a button in the navigation bar is pressed, the first UIWebView will be removed from the subview and the next one will be added instead.
The problem is, that if I'm running the application in landscape (both iPhone and iPad) after the second UIWebView is added, the WebView is not filling the entire screen. Why?
You can download the small sample project here: http://uploads.demaweb.dk/WebView.zip.
I dont know why but this inside your action method will do the trick...
UIWebView *newWebView=[[UIWebView alloc] init];
newWebView=[self.webViews objectAtIndex:1] ;
newWebView.frame=self.view.frame;
self.webView = newWebView;
hope this helps.. :/

Loading bar over status bar?

I've seen several apps do this, and i've been wondering how it's done. If you look at the Wunderkit app, when it loads something, there's a blue animated bar that slides down to cover the status bar until it finishes loading. How is this done?
you can subclass UIWindow.
And set it windowLevel = UIWindowLevelStatusBar;
code:
#interface CHLoadingWindow : UIWindow
#implementation CHLoadingWindow
- (id)init
{
self = [super init];
if (self) {
self.windowLevel = UIWindowLevelStatusBar;
// then draw your UI
}
return self;
}
#end
use it:
CHLoadingWindow *loading = [[CHLoadingWindow alloc] init];
[loading makeKeyAndVisible];
discover it:
[loading release];
loading = nil;
[[[[UIApplication sharedApplication] windows] objectAtIndex:0] makeKeyWindow];

UITabBarItem finishedImageSelected placed offsetting the tab bar

I'm trying to customize UITabBarItem but I'm having problems with the image's position.
The image size is 81px x 49px, the same height as the UITabBar. This is how I set the image:
// AppDelegate
BlocosController *blocos = [[[BlocosController alloc] initWithManagedObjectContext:moc] autorelease];
UINavigationController *navBlocos = [[[UINavigationController alloc] initWithRootViewController:blocos] autorelease];
tabBarController = [[UITabBarController alloc] initWithManagedObjectContext:moc];
tabBarController.viewControllers = [NSArray arrayWithObjects: navData, navBlocos, navBairro, navAtualizar, nil];
// ...
// BlocosController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:TITLE image:nil tag:10] autorelease];
[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:#"tab_bar_blocos_selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab_bar_blocos_unselected"]];
}
return self;
}
I've search on google and found this tutorial, the code uses the same API as I use and works as expected. The code in this article behaves just like mine, but since their background is the same color there's a illusion of it been correctly placed.
Why is the finishedImageSelected and the unselected are placed unaligned with the tab tab? How to fix it?
I've found the correct way to accomplish this and made a post: felipecypriano.com/2012/02/27/….
Basically the problem is that finishedImage is the icon not the icon and the background, it's possible to use with the background by adjusting the imageInset property.