Navigation controller affecting app overall background image - objective-c

I have an application where when it begins, it loads a viewController which loads the Default.png launch image and holds it there for 1.5 seconds, then that image fades out, then fades into another image which will be the background image for my entire application. From here it loads the first viewController and then the buttons and navigation bar fade in.
So it goes SplashScreeVC - Default.png presented
Default.png Fades out
New Image fades in (This is the apps overall background image)
Loads MainVC with buttons and nav bar alpha set to 0.1.
Method called to fade in the nav bar and the buttons in the mainVC
So in my app Delegate I have this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
SplashVC *splash = [[SplashVC alloc] initWithNibName:#"SplashView" bundle:nil];
self.window.rootViewController = splash;
[self.window makeKeyAndVisible];
return YES;
}
So the app loads with the Default.png, which then loads the splashVC which has the Default.png as its background image, this is shown for 1.5 seconds. I then have a some methods to fade out this image, and then fade in the image that will be used as the background image for the entire application. Then it calls the appDelegates MainNav method which loads the Navigation controller. The app Delegates MainNav method is below
-(void) MainNav
{
UIViewController *main = [[MainVC alloc] initWithNibName:#"MainView" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:main];
UIImage *navImage = [UIImage imageNamed:#"NavBarGrey.png"];
//Add the custom image
[[self.navController navigationBar] setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];
//[[UINavigationBar appearance] setTintColor:UIColorFromRGB(0xee2e24)];
[[UINavigationBar appearance] setTintColor:UIColorFromRGB(0xe7e7e7)];
self.navController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"backgroundImage.png"]];
self.window.rootViewController = self.navController;
}
The problem is when it moves from the SplashScreen VC to the MainVC, the image suddenly jerks up despite the fact it is the same image that fades in in the SplashVC.
Does anyone have any idea why this is? I am guessing it has something to do with the navigation controller affecting the image size, but not sure what to do to fix it? Do I need to create a new image for the navigation bar background with different dimensions? Or is there another way I can fix this issue?
Any advice would be much appreciated. Thanks!!
Edit: Fixed image jerking to the right, had image width at wrong height, but the image is still jumping up a set amount

Managed to figure it out. Seems to have to make a copy of the image and increase its height by 20 pixels and set that as the navigation bars background image. This offsets the navigation bar problem.

you can set bacround image code like
yourView.setBacroundColur=[UIColour colourWithImagePttern:[UIImage ImageNamed:#""]];

Related

Adjust SearchBar size in Navigation Bar when Orientation changes to Landscape iOS7

I'm using a Storyboard where I have a UIViewController embedded in a Navigation Controller. I have placed a SearchBar into the Navigation Controller "replacing" the TextView item with it. It works as expected in portrait.
The problem is when I rotate it to Landscape, where the Searchbar remains in the center and its height seems to be bigger than the Nav Bar.
I have tried configuring the constraints, but it hasn't been successful.
Could you help me please?
Set Constraints to your Search bar.. It will shows the magic.
I fixed it adding the search bar in the title view, this way:
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[self.searchBar setPlaceholder:#"Buscar Recetas"];
[self.searchBar sizeToFit];
[self.searchBar setDelegate:self];
[self.navigationItem setTitleView:self.searchBar];
Note that I'm not using a search display controller in this case. Search Display Controller already has a property where you can set the search bar in the navigation bar, like this:
self.searchdisplaycontroller.displaysSearchBarInNavigationBar = YES;

Visible buttons with transparent navigation bar

I've seen several apps that have completely transparent navigation bars but with visible buttons, I cant seem to find anything that wont make the button invisible as well. I'm sure they were using UINavigationController for the navbar because it had the same animations with fade and what not.
Im currently using this code in ViewDidLoad and ViewDidAppear to either hide or show the nav bar because it's not supposed to be on the first page-
[self.navigationController setNavigationBarHidden:NO animated:YES];
and this code for its transparency:
[self.navigationController.navigationBar setAlpha:0.0];
Create a subclass of UINavigationBar containing no methods except drawRect:. Put custom drawing code there if you need to, otherwise leave it empty (but implement it).
Next, set the UINavigationController's navigation bar to this subclass. Use initWithNavigationBarClass:toolBarClass: in code, or just change it in the Interface Builder if you're using storyboards/nibs (it's a subclass of your UINavigationController in the hierarchy at the side).
Finally, get a reference to your navigation bar so we can configure it using self.navigationController.navigationBar in the loadView of the contained view controller. Set the navigation bar's translucent to YES and backgroundColor to [UIColor clearColor]. Example below.
//CustomNavigationBar.h
#import <UIKit/UIKit.h>
#interface CustomNavigationBar : UINavigationBar
#end
//CustomNavigationBar.m
#import "CustomNavigationBar.h"
#implementation CustomNavigationBar
- (void)drawRect:(CGRect)rect {}
#end
//Put this in the implementation of the view controller displayed by the navigation controller
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = YES;
[self navigationController].navigationBar.backgroundColor = [UIColor clearColor];
}
Here's a screen shot of the result, mimicking Plague.
The blue border was drawn in drawRect: to show you that a UINavigationBar is there and not just a button and a label. I implemented sizeThatFits: in the subclass to make the bar taller. Both the button and label are UIView's containing the correct UI element that were placed in the bar as UIBarButtonItems. I embedded them in views first so that I could change their vertical alignment (otherwise they "stuck" to the bottom when I implemented sizeThatFits:).
self.navigationController.navigationBar.translucent = YES; // Setting this slides the view up, underneath the nav bar (otherwise it'll appear black)
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
//remove shadow
[[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];
To make the Navigation Bar transparent, use the below code:
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = YES;
After this set the background image of the Navigation Bar the same as the view behind it using the below property:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"SAMPLE.jpg"] forBarMetrics:UIBarMetricsDefault];

IOS 6 navigationController navigationbar

I just updated my phone to IOS 6 but I have some issue regarding adding UIImageView on the UINavigationController navigationbar. This is my code
UIImage *logoImage = [UIImage imageNamed:#"navigationbar.png"];
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:logoImage];
UINavigationBar *navBar = self.navigationController.navigationBar;
[navBar addSubview:logoImageView];
[logoImageView release];
This will add logo on navigationbar, it works great on the lower version of IOS 6. But on IOS 6 the logo shown but the back button was behind the logo so back button is not shown.
I don't want to override the UINavigationBar drawrect since I also have UINavigatioBar somewhere on the code for popup.
Any suggestions?
I think you don't need a UIImageView in IOS 6.
You can just put a background image in the UINavigationBar (for example in AppDelegate) like this:
[[UINavigationBar appearance] setBackgroundImage :[UIImage imageNamed:#"navigationbar"]];
Found a good site which explains some new user interface customisation in IOS 6:
click here

how to pop a drawing uiview as a model view only half of the screen

I create new viewcontroller class with xib then created uiview inherited class and in xib file custom class I wrote the uiview inherited class name(PaintView).
I am trying to implement a simple drawing feature in my app, I created a simple drawing code which paints on uiview using touchbegain, thouchmoves, drawrect methods in PaintView class.
Till here its all working fine now I want to pop a model of this view, but I want it to display half of the screen, I resize it in interface builder but it is still showing on full screen.
Other posts says create a transparent view add contents at bottom half thats how you will get half model view, but this is not a solution for my problem.
How to properly pop model view but only half of the screen.
Simple, don't present it modally.
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
[controller.view setFrame:CGRectMake(0, 480, 320, 320)];
[self.view addSubview:controller.view];
[UIView animateWithDuration:0.5 animations:^{
[controller.view setTransform:CGAffineTransformMakeTranslation(0, -320)];
}];
To change the color's I recommend you store the integer values of your color's hues into an array, that way you can stably assign the hue from the integer value of some object in the array:
arrayOfColors = [[NSArray alloc] initWithObjects:#"0.0", #"0.1", #"0.2", #"0.3", #"0.4", #"0.5", #"0.6", #"0.7", #"0.8", #"0.9", nil];
[[UIColor colorWithHue:[[arrayOfColors objectAtIndex:someIndex]floatValue] saturation:1.0 brightness:1.0 alpha:1.0]setStroke];

In Cocoa-Touch Framework, is there any modal view in iPad like this?

Is there any model view like this on the iPad?
Yes, there is:
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
For example:
UIViewController *viewController = [[UIViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:viewController animated:YES];
viewController.view.superview.frame = CGRectMake(0, 0, 540, 500); // this is important to do this after presentModalView
viewController.view.superview.center = self.view.superview.center;