iPhone 5 UI screen issues - objective-c

After lot of googling i am asking this question. I have an app, i want to make it compatible with the iPhone5. I added Default-568h#2x to my app which contains nearly 10views. So I changed views like this..
In viewDidLoad:
if ([[UIScreen mainScreen] bounds].size.height >= 568) {
self.view.frame = CGRectMake(0, 0, 320, 568);
//iPhone5
}
else {
}
window.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
I have made this change in my didFinishLaunching with options:
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
After doing like this I found Some issues..
The bottom of the screen i.e 88px long is not touchable even the controls placed on it - for this i have set FullScreenAtLaunch checked in attributes of MainWindow.xib, but doesn`t worked
I have textbox on view, when it is focussed keyboard is coming but on top of the Keyboard view coming, how to get rid of that.
How to resolve this, any help would be greatly appreciated.
Thanks

This because in the line where you create your UIWindow in the App delegate class you will probably have something like this:
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,480);
change it to something like:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
also where you now do:
if ([[UIScreen mainScreen] bounds].size.height >= 568) {
self.view.frame = CGRectMake(0, 0, 320, 568);
//iPhone5
}
else {
}
You coud as well do:
self.view.frame = [[UIScreen mainScreen] bounds];
But most of the time this ins't needed since the view of the viewcontroller will take op the space correctly. If you have set the AutoResizeMasks in interface builder correctly you will not gave to set the frame in code.

Related

Objective-C: Status Bar Alpha

I am creating a custom alert view and I am setting the background of this view to a mostly alpha black, to cause the background view to appear slightly faded. This works except for with the status bar (it stays the exact same).
With the current Apple AlertView framework, when the alert view is shown, the entire background fades slightly. How can I replicate this functionality?
EDIT
None of the answers are solving this for me. Here is what I'm doing doing to open the AlertView:
[self.navigationController.view.superview addSubview:self.alertViewController.view];
Then from the custom alert view controller in viewDidLoad():
self.view.backgroundColor = COLOR_BLACK_ALPHA;
You can't change the alpha of the status bar, you can only set its appearance.
UIAlertView is an Apple component and as such uses private API's to do things that you can't.
What I suggest is that before showing your view, take a snapshot of the screen beneath it using something like this (source : Capture iPhone screen with status bar included
UIView *screenshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO];
than remove the status bar, and place the image, blur the image (can be done using a blur view, or just as an effect on the image, then show your view.
If you have any questions please ask.
How about this?
UIWindow *customWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
customWindow.windowLevel = UIWindowLevelStatusBar+1;
customWindow.hidden = NO;
customWindow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
[customWindow makeKeyAndVisible];
Now inside customWindow you can add whatever you want...
You can do this by adding a custom overlay in Window before you add your custom alert view like this:
UIWindow *aMainWindow = [[UIApplication sharedApplication] keyWindow];
self.grayOverlayView = [[MyCustomAlertViewOverlay alloc] initWithFrame:aMainWindow.bounds];
self.grayOverlayView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
[aMainWindow addSubview:self.grayOverlayView];
[aMainWindow addSubview:self.customAlertView];
And this is how your overlay would look like:
#implementation MyCustomAlertViewOverlay
- (void)drawRect:(CGRect)iRect {
CGContextRef aContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(aContext);
CGColorRef aGradientStartColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0].CGColor;
CGColorRef aGradientEndColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.6].CGColor;
NSArray *aColors = [NSArray arrayWithObjects:(__bridge id)aGradientStartColor, (__bridge id)aGradientEndColor, nil];
CGFloat rLocations[2] = {0.0 , 0.5};
CGColorSpaceRef rColorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef rGradient = CGGradientCreateWithColors(rColorSpace, (CFArrayRef) aColors, rLocations);
CGColorSpaceRelease(rColorSpace);
CGPoint aCenter = CGPointMake(iRect.origin.x + iRect.size.width / 2, iRect.origin.y + iRect.size.height / 2);
CGContextDrawRadialGradient(aContext, rGradient, aCenter, 0, aCenter, iRect.size.height, kCGGlyphMax);
CGContextSetRGBFillColor(aContext, 0, 0, 0, 0.0);
CGGradientRelease(rGradient);
CGContextFillRect(aContext, iRect);
CGContextRestoreGState(aContext);
}

Splash screen animation is not supporting with Xcode 7 GM(iOS9). App crashes with an error

In my application i am using the below code to show an animated splash screen. App working fine in Xcode-6.4(iOS 8), but coming to Xcode-7GM version(iOS9) app crashes with an error.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
// Build array of images, cycling through image names
for (int i = 1; i <= IMAGE_COUNT; i++)
[imageArray addObject:[UIImage imageNamed:
[NSString stringWithFormat:#"image__%d.png",i]]];
animationImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
animationImageView .animationImages=[NSArray arrayWithArray:imageArray];
// One cycle through all the images takes 3.5 seconds
animationImageView .animationDuration = 3.5;
// Repeat forever
animationImageView .animationRepeatCount = 0;
// Add subview and make window visible
[window addSubview:animationImageView ];
[window makeKeyAndVisible];
// Start it up animations
[animationImageView startAnimating];
// Wait 3.5 seconds, then stop animation
[self performSelector:#selector(stopAnimation) withObject:nil afterDelay:3.5];`
This is the error message what i am getting while using Xcode-7GM:
Assertion failure in -[UIApplication
_runWithMainScene:transitionContext:completion:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UIApplication.m:3294
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
change to
[window setFrame:[[UIScreen mainScreen] bounds]];
It sounds like you're trying to do some networking. In iOS 9, by default, all network communication must be secure. If you are trying to do an http: request, it will fail; you must use https: (unless you switch this feature off in your Info.plist).
I had the same issue, it has been solved by removing [window makeKeyAndVisible];.
The self window needs to be set as root view controller in your didFinishLaunchingWithOptions: :
[self.window setRootViewController:navController];
For me like jonmo, this error was the result of not defining rootViewController prior to exiting didFinishLaunchingWithOptions.
Doing so resolved this issue for me.
Prior to Xcode 7, it was just a warning now it seems to be a hard stop
In my case, the solution to this error message was updating an included CocoaPods dependency called Loopback (that I believe adds an extra UIWindow to the app.)
I had the same issue, It has been solved by replacing the below line of code in Appdelegate.m
[window addSubview:viewController.view];
with
[window setRootViewController:viewController];

How to add dimmed background to a custom UIPopoverBackgroundView

I am making custom popover by subclassing UIPopoverBackgroundView (using this tutorial) and presenting it by using UIPopoverController. Unfortunately as soon as I specify custom popoverBackgroundViewClass the native dimmed background disappears. Is there any way to leave the dimmed background when using custom UIPopoverBackgroundView? Any other solution that I can use to simulate native behaviour?
Not sure why this got down voted, it's a good question because when you implement a custom UIPopoverBackgroundView, the dimmed background doesn't get set. In researching this problem, I determined the best approach is to set it myself!
Just before creating the popover view, I create a "mask view" that will be added to the view before the popover. This code includes a nice fade in effect as well:
self.customPopoverMaskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.customPopoverMaskView.backgroundColor = [UIColor blackColor];
self.customPopoverMaskView.alpha = 0.3f;
[UIView transitionWithView:self.view
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.view addSubview:self.customPopoverMaskView];
}
completion:nil];
And to remove the view, plug this into the method(s) that handle the popover view disappearing:
[UIView transitionWithView:self.view
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.customPopoverMaskView removeFromSuperview];
}
completion:nil];
Works well for me. Happy coding!
Aaron
All you need is add next code into initWithFrame: method of your implementation of UIPopoverBackgroundView.
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0 - self.frame.origin.x,
0 - self.frame.origin.y,
[UIScreen mainScreen].bounds.size.width,
[UIScreen mainScreen].bounds.size.height)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.15;
dimView.userInteractionEnabled = NO;
[self addSubview:dimView];
It works as same as default Apple implementation.

ios 7 status bar and navigation bar issue

My app's view is overlapped with status bar and navigationBar in ios7 device so I tried lots of solutions
uncheck 'under top bars' property in storyboard
self.edgesForExtendedLayout = UIRectEdgeNone;
set delta y to -20 in storyboard...
but none of these worked.
My last trial was adding these lines to appdelegate's didFinishLaunchingWithOptions
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
application.statusBarStyle = UIStatusBarStyleLightContent;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.window.clipsToBounds =YES;
} else {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
It works quite well when navigation bar is hidden but when nagivigation is not hidden,
navigationbar's frame is (0, 20, 320, 44) not (0, 0, 320, 44)
So navigationBar's height seems to be 64..
why is this? Hope someone explains me!
Thanks is advance :)
For a better explanation of the differences please see this transition guide (link).
Make sure you set this in viewWillAppear:
self.navigationController.navigationBar.translucent = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
To avoid the overlapping with the UINavigationBar, you must set its translucent property to NO.
As for the status bar, you have to manually set it by specifying its style and then reposition the whole window's frame. I would add on top of that an iOS 7 condition to make sure that only happen with users running iOS 7.
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height - 20);
}

UIView size is not as expected to be

I can't figure out why that view takes the entire screen.
In AppDelegate file
...
self.viewController = [[[ViewController alloc]init]autorelease];
[self.window setRootViewController:self.viewController];
self.window.backgroundColor = [UIColor whiteColor];
..
In ViewController.m
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 30, 30)];
[view setBackgroundColor:[UIColor greenColor]];
self.view = view;
When I run the app the screen is entirely green instead of having just a square in green.
What is wrong here ?
The erroneous line is here:
self.view = view;
When you set a view of a UIViewController that is the root controller, it is guaranteed to fill the screen. Instead, add it as a subview:
[self.view addSubview:view];
And you should be fine.
The view controller automatically manages the size of its root view (self.view), so even if you initialize it with a smaller size it will later get resized to fill the screen. This resizing conveniently also happens when the interface orientation changes (see the answer this question).
As suggested by Richard's answer, you can add your green view as a subview to the controller's root view. The crash you get is probably because the root view does not exist yet when you try to access it. Try the following:
- (void) loadView
{
[super loadView]; // creates the root view
UIView* subView = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 30, 30)];
[subView setBackgroundColor:[UIColor greenColor]];
// because you don't set any autoresizingMask, subView will stay the same size
[self.view addSubview:subView];
}