iPad

iOS Navigation Bar behind status bar after closing full screen MPMoviePlayer

I had a problem with an iOS app I am creating. I have a view that has a UINavigationBar at the top and a table view  that displays a full screen video on didselectrowatindexpath. Once the video is playing if the device is rotated and the done button is pressed the video will disappear but the navigation bar has moved to the top of the screen displaying behind the status bar. This leaves a gap between the nav bar and the top of the table view.

Solution

I tried a number of things to fix it including setting the status bar to hidden and then not hidden once video had exited full screen. I also tried the same with the navigation bar.

The fix that actually worked in the end did follow these lines. I added observers to MPMoviePlayer notifications and hid the nav bar when the video entered full screen mode. Once the video exited full screen mode I showed the nav bar again.

 
Below are how you add the observers that are required. I placed them in the viewDidLoad method.

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didExitFullScreen:)
                                                 name:MPMoviePlayerDidExitFullscreenNotification
                                               object:nil];
 
[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(didEnterFullScreen:)
                                                 name:MPMoviePlayerDidEnterFullscreenNotification
                                               object:nil];

I then created the methods to hide and show the navigation bar. These methods can include any other UI updates you might need to do such as refreshing a table view.

-(void)didEnterFullScreen:(id)sender{
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
 
-(void)didExitFullScreen:(id)sender{
    [self.navigationController setNavigationBarHidden:NO animated:NO];
 }

After creating these the Navigation bar behaved as expected and no longer displayed behind the status bar.
There is still one more step to the process and that is removing the observers to the notifications. I added these to the dealloc method

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidEnterFullscreenNotification object:nil];

iOS – Check if wifi is being used

In an app I was making recently I wanted to check if the user was using a wifi connection. I used the method below to check and just checked whether it returned true or false.

- (BOOL)networkCheck{
 Reachability *currentReachability = [[Reachability reachabilityForInternetConnection] retain];
 NetworkStatus networkStatus = [currentReachability currentReachabilityStatus];
 [currentReachability release];
switch (networkStatus)
 {
 case NotReachable: {
 NSLog(@"Not connected");
 return false;
 break;
 }
 
case ReachableViaWWAN:{
 NSLog(@"Cellular Network");
 return false;
 break;
 }
 
case ReachableViaWiFi:{
 NSLog(@"Wifi");
 return true;
 break;
 }
 }
 
return false;
}

ShareKit 0.2.1 Twitter not working

I added ShareKit to my project and got the following error:

Twitter Send Status Error: {"error":"Could not authenticate with OAuth.","request":"\/1\/statuses\/update.json"}

The following is how I fixed it:
Around line 54 you will see the following code:

self.authorizeURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/authorize"];
self.requestURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"];
self.accessURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];

These need to be changed to https://api.twitter.com/oauth rather than https://twitter.com.

NGTabBarController for iOS

A custom TabBarController which can be positioned on the bottom, top, left or top. Utilizes iOS 5 Containment API if possible, but works on iOS 4 too. The TabBar is fully customizable with a tintColor or background image as well as the possibility to show/hide the item highlight and the possibility to change the text colors, have image-only tabBar items etc.
Download the source code here

NGColoredViewController *vc1 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc2 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc3 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc4 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
NGColoredViewController *vc5 = [[NGColoredViewController alloc] initWithNibName:nil bundle:nil];
 
vc1.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Home" image:image1];
vc2.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Images" image:image2];
vc3.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Live" image:image3];
vc4.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Contact" image:image4];
vc5.ng_tabBarItem = [NGTabBarItem itemWithTitle:@"Settings" image:image5];
 
NSArray *viewController = [NSArray arrayWithObjects:vc1,vc2,vc3,vc4,vc5,nil];
 
NGTabBarController *tabBarController = [[NGTestTabBarController alloc] initWithDelegate:self];
 
tabBarController.animation = NGTabBarControllerAnimationMoveAndScale;
tabBarController.layoutStrategy = $isPhone() ? NGTabBarLayoutStrategyEvenlyDistributed : NGTabBarLayoutStrategyCentered;
tabBarController.itemPadding = 10.f;
tabBarController.showsItemHighlight = NO;
tabBarController.tintColor = [UIColor redColor];
tabBarController.viewControllers = viewController;
self.window.rootViewController = tabBarController;

NGTabBarController was created by Matthias Tretter (@myell0w).

iOS Launch Images

When creating a new universal IOS app you need to create a minimum of 6 launch images to support the iPhone and iPad (both including their retina displays).

For the iPhone you have it easy, only 2 are required.

Default.png – 320 x 480
Default@2x.png – 640 x 960 

For the iPad there are a few more:

Default-Portrait.png – 768 x 1004
Default-Portrait@2x.png – 1536 x 2008
Default-Landscape.png – 1024 x 748
Default-Landscape@2x.png – 2048 x 1496

You can specify images for Landscape Right and Left and also Portrait Upside Down using the names below:

Default-LandscapeLeft.png
Default-LandscapeRight.png
Default-PortraitUpsideDown.png

For more information on Custom images and icons visit the apple developer site

How to change colour of UINavigationBar

By default the UINavigationBar on an iOS app is blue. Apple have some built-in styles that you can use

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];

The options available are:

  • UIBarStyleBlack
  • UIBarStyleBlackOpaque
  • UIBarStyleBlackTranslucent
  • UIBarStyleDefault

*UIBarStyleBlackOpaque and UIBarStyleTranslucent have been depreciated. You should use UIBarStyleBlack and set property ‘translucent’ to yes if needed*.

You can also change the colour to any colour you wish using one of the two lines of codes below and adjusting the colour values.

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.7 green:.5 blue:.2 alpha:1];
 
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
 Scroll to top