Black status bar bug iOS - ios

everybody.
Guys, I have a problem with status bar in my project..
In default , in app status bar should hidden. This is work, but one view have a bug with status bar like on screenshot.
On main menu it's have black color and don't hidden(
In singleton I'm initialise background image for different devices, and this is work for all views in app))
This is my code singleton init background:
// background return
- (UIColor *)mainBackground:(UIInterfaceOrientation)orientation {
UIColor *color;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
color = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundIpad.png"]];
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
color = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundLandspIpad.png"]];
}
} else {
color = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
}
return color;
}
//return wight screen
- (float)wightScreen {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
return 768;
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
return 1024;
}
}
return wight();
}
//return rect view all for screens
- (CGRect)refreshPoints {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
return CGRectMake(0, 0, 768, 1024);
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
return CGRectMake(0, 0, 1024, 768);
}
} else {
return CGRectMake(0, 0, 320, height());
}
return CGRectMake(0, 0, 768, 1024);
}
And this is code in controller view, where I'm have a problem:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return [[Singleton sharedInstance] getSelf:#"MainMenuController"];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[PostRequest sharedInstance] userInfo];
self.view.backgroundColor = [[Singleton sharedInstance] mainBackground:[[UIApplication sharedApplication] statusBarOrientation]];
// if (iphone4()) {
// [self newRectNiewIphone];
// }
}
I'm hope in yours help!

This is screenshot with bug status bar
http://i.stack.imgur.com/nfiZ3.png
And screenshot, how on another views
http://i.stack.imgur.com/wVadC.png

You need to set
self.automaticallyAdjustsScrollViewInsets=NO;
On the viewController in the viewDidLoad method.

Related

iAd in UITableViewController

I have a UITableViewController that I want to add iAds to. I want the ad to display at the bottom of the screen at all times. I have followed the answer here: https://stackoverflow.com/a/9857798/2584268 and have achieved this behavior. However, the ad is hidden in the beginning and only appears when the user scrolls the table. How can I get the ad to appear at the bottom of the screen when the view loads, not just when the user scrolls?
To show the ad when the view appears, I add the banner view on viewDidAppear.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_myIAD = [[self appdelegate] myIAD];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
//iPhone code
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 50, 320, 50);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 114, 320, 50);
}
}
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 32, 480, 32);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 84, 480, 32);
}
}
}
else
{
//iPad code
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 768, 66);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 768, 66);
}
}
else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 1024, 66);
}
else
{
_myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 1024, 66);
}
}
}
[self.view addSubview:_myIAD];
}
There is a ton of code in there to deal with iOS6.1 and iPads and iPhones, but it works real well. I always like to use the statusBarOrientation to find the orientation, it works better.
As you can see there is a line
_myIAD = [[self appdelegate] myIAD];
I actually make the banner in the app delegate and use it in all the view controllers. To handle rotation, I register for a notification in viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(updateUI:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
And basically use the same code in the viewDidAppear in the method updateUI:
The only other thing I did was to put in this code to keep the iAd at the bottom.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _myIAD.frame;
frame.origin.y = _myTableView.contentOffset.y + _myTableView.frame.size.height-_myIAD.frame.size.height; // Move view to the bottom on scroll
_myIAD.frame = frame;
[_myTableView bringSubviewToFront:_myIAD];
}

iPad iOS7 Orientation Problems

I have an app that changes the view when the orientation changes using: [[UIApplication sharedApplication] statusBarOrientation]. On the iPhone, it works but on the iPad, it gives me landscape instead of portrait and portrait instead of landscape.
When I call the getRelevantFrame method outside of the UIDeviceOrientationDidChangeNotification, it will return the correct frame.
It will return the opposite frame (if landscape, will return portrait and vice versa) when responding to the notification.
Both the versions (iPod/iPhone + iPad) uses the same code but this only breaks on the iPad version
Here is the code I used to calculate the relevant frame:
EDIT: Used rob5408's advice. Changed to use UI_USER_INTERFACE_IDIOM().
+ (CGRect)getRelevantFrame {
//Get orientation
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { //iPhone/iPod
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
return [self frameiPhoneLandscape];
}
else {
return [self frameiPhonePortrait];
}
} else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { //iPad
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(#"iPad Landscape");
return [self frameiPadLandscape];
}
else {
NSLog(#"iPad Portrait");
return [self frameiPadPortrait];
}
}
return CGRectMake(0, 0, 0, 0);
}
Here is the notification I used:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
Here is the code I used to read the orientation change:
- (void) didRotate:(NSNotification *)notification
{
NSLog(#"Parent: %#", self.parentController);
if(self.parentController) {
[self setFrame:[TASFrames getRelevantFrame]];
}
}
I transferred the code to a new project. And now it works as it's supposed to. No idea as to why this happens. Code didn't change.

How can I make the BarcodeScanner plugin works in the landscape mode?

I am developing a iOS app using Cordova, and I download the Cordova Barcode Scanner Plugin from this link.
However, it only works in portrait mode.
I make some changes in CDVBarcodeScanner.mm.
#pragma mark CDVBarcodeScannerOrientationDelegate
- (BOOL)shouldAutorotate
{
return YES;// NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll; // UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:#selector(shouldAutorotateToInterfaceOrientation:)]) {
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
return YES;
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
// [CATransaction begin];
//
// self.processor.previewLayer.orientation = orientation;
// [self.processor.previewLayer layoutSublayers];
// self.processor.previewLayer.frame = self.view.bounds;
//
// [CATransaction commit];
// [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
[UIView setAnimationsEnabled:NO];
AVCaptureVideoPreviewLayer* previewLayer = self.processor.previewLayer;
previewLayer.frame = self.view.bounds;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
[previewLayer setOrientation:AVCaptureVideoOrientationLandscapeLeft];
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
[previewLayer setOrientation:AVCaptureVideoOrientationLandscapeRight];
} else if (orientation == UIInterfaceOrientationPortrait) {
[previewLayer setOrientation:AVCaptureVideoOrientationPortrait];
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
[previewLayer setOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
}
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[UIView setAnimationsEnabled:YES];
}
I can rotate to the Landscape mode now, but it still only work in the portrait mode.
How can I fix it?
According to the solution, I delete if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {} in zxing-all-in-one.cpp.
However, it only works in landscape now.
On zxing-all-in-one.cpp file,
change
if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {}
to
if (result.empty()) {}
You can also modify the CDVBarcodeScanner.mm. Just replace all ***Portraits with LandscapeLeft/LandscapeRight -> I prefer LandscapeLeft.

"[[UIApplication sharedApplication] statusBarOrientation]; gives wrong value in the first call"

I'm working on an iPad app that start with a splash screen and then moves to the login screen. My app should support all the orientation, and iOS 4.3 and later. To do that, I added the four orientations in the plist, and the following code in the app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
// Override point for customization after application launch
SplashViewController *aController = [[SplashViewController alloc] initWithNibName:#"SplashView" bundle:nil];
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].bounds;// no effect
[window setFrame:[[UIScreen mainScreen] bounds]]; //no effect
//[window addSubview:[mainViewController view]];
[window setRootViewController:mainViewController];
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
In the splash screen
- (void) loadView {
[super loadView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged) name:#"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (void) orientationChanged
{
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
NSLog(#"Portrait");
else
NSLog(#"Landscape");
}
Here I get the correct orientation but when rotating, I get an inverted result, I get landscape for portrait and portrait for landscape. I tried to convert the code like this:
- (void) orientationChanged
{
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
NSLog(#"Landscape");
else
NSLog(#"Portrait");
}
I get the first result wrong, after that the result is correct. can you help?
note that I have put some uielement to test and the test come with the same result.
Thank you
I managed to solve this matter after two days of searching and testing, none of the answers in the forum was complete, and here is how I solved:
//this for the orientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self orientationChanged];
}
// here is the tricky thing, when startup you should have a special function for the orientation other than the orientationchanged method, and must be called here in viewDidAppear, otherwise it won't work
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self StartUpOrientation];
}
#pragma mark -
#pragma mark Orientation Methods
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (void) orientationChanged {
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft && interfaceOrientation != UIInterfaceOrientationLandscapeRight) {
[self.view setBounds:CGRectMake(0, 0, 1024, 748)];
// your code here
}
else {
[self.view setBounds:CGRectMake(0, 0,768,1004)];
//your code here
}
}
- (void) StartUpOrientation {
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft && interfaceOrientation != UIInterfaceOrientationLandscapeRight) {
[self.view setBounds:CGRectMake(0, 0,768,1004)];
// your code here
}
else {
[self.view setBounds:CGRectMake(0, 0, 1024, 748)];
// your code here
}
}
hope it will help someone someday

iPad start in Landscape receive only touch within 768x768

It works perfect fine when starting in portrait and also works when you rotate from portrait to landscape and back.
It does not work when starting in landscape. But then it works when you rotate from landscape to portrait and back.
In landscape starting mode, the screen does not respond with any touch where screen coordinateX greater than 768.
What happens in code is, I use status bar orientation to determine original orientation and rotate each view manually. The views display correctly but does not receive touch properly.
Then my root view controller will get called when ipad start rotating with:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
which will rotate every subviews.
Root controller:
- (void)loadView {
self.view = [[UIView alloc]init ];
//initialize child views
[self willRotateToInterfaceOrientation:0 duration:0];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if ([model isLandscape]) {
self.view.frame = CGRectMake(0, 0, 1024, 768-80);
}
else {
self.view.frame = CGRectMake(0, 0, 768, 1024-80);
}
//rotate child views
}
My code [model isLandscape] works so I don't need to provide details as to how it works but here are the code anyway:
- (bool)isLandscape {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
return true;
else
return false;
}
-(id) init
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation];
if (curOrientation == UIDeviceOrientationPortrait ||
curOrientation == UIDeviceOrientationPortraitUpsideDown ||
curOrientation == UIDeviceOrientationLandscapeLeft ||
curOrientation == UIDeviceOrientationLandscapeRight)
{
orientation = curOrientation;
((AppDelegate*)([UIApplication sharedApplication].delegate)).savedOrientationForRestart = orientation;
NSLog(#"changed");
}
}
-(void)validateOrientation { //first time when initializing orientation
UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation];
if (curOrientation != UIDeviceOrientationPortrait &&
curOrientation != UIDeviceOrientationPortraitUpsideDown &&
curOrientation != UIDeviceOrientationLandscapeLeft &&
curOrientation != UIDeviceOrientationLandscapeRight)
{
orientation = [[UIApplication sharedApplication] statusBarOrientation];
}
}
OK. so it turns out among the tens of backgrounds and layers some were not rotated to landscape/portrait correctly...it was extremely hard to debug this issue...
in the end, I hooked up a touch debugger to see which views are receiving touch correctly and which are not...
extremely helpful!
Just use the UIWindow subclass below instead of UIWindow in your code, should work.
#import <UIKit/UIKit.h>
#interface MyUIWindow : UIWindow {
}
-(void)rotate;
#end
and
#import "MyUIWindow.h"
#implementation MyUIWindow
-(id) init{
self = [super init];
if(self)
{
}
return self;
}
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
NSSet *touches = [event allTouches];
if (touches.count != 1)
return;
UITouch *touch = touches.anyObject;
UIView * view = touch.view;
NSLog(NSStringFromClass([touch.view class])); //this prints out touch view
}
#end

Resources