UIImageView over Navigation bar and main screen - ios

I have an UImage that I need half on the navigation bar and half on the main screen. I have added a Navigation Controller on my project so now I have a nav bar on all screens. I need a square image to go half on the navigation controller and half on the main screen.
In XCODE I have successfully put an UImageView over the nav bar and the main screen but when i put an image on it i only appears in the part thats over the main screen and not over the navigation bar. I don't want to split the image so I can use Navigationbar.image control - is there another way ?

Instead of adding it to viewController, add it to window.
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(40, 30,240,60)];
view.backgroundColor =[UIColor greenColor];
[[[UIApplication sharedApplication] delegate].window addSubview:view];

As you might have noticed the UINavigationBar appears on top of everything you have within your UIViewController's view.
One way of overcoming this is by adding your UIImageView to the keyWindow like so:
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image = [UIImage imageNamed:#"myImage"];
[[UIApplication sharedApplication].keyWindow addSubview:imageView];

Related

How to show navigation bar top and tool bar below when showing uiimage in full screen?

-(void)imageFullScreen:(UITapGestureRecognizer*)sender{
modalCon = [[UIViewController alloc] init];
modalCon.view.backgroundColor=[UIColor blackColor];
modalCon.view.userInteractionEnabled=YES;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:modalCon.view.frame];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = self.mImageView.image;
[modalCon.view addSubview:imageView];
UITapGestureRecognizer *modalTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissModalView:)];
[modalCon.view addGestureRecognizer:modalTap];
[self.delegate showFullScreen:modalCon];
return;
}
The method showFullScreen:modalCon will show the modalViewController(modalCon) and on touch of image shown, it will dismiss. But when image is full screen, the navigation bar is not shown (black bars come both above and below the image) like this:
But I want same behaviour as iOS photos app does on click of any photo in library where a navigation bar comes up and tool bar down with multiple buttons comes and edit, back, share, delete options come like this :
You can always try this https://github.com/mwaterfall/MWPhotoBrowser
Credits to Michael Waterfall
Create a view from storyboard
Embedded it with navigation bar
Setup title and edit button in viewcontroller file
Add image view and and uiview
UIview contains tableview and the 3 buttons
table view you have to manage scroll and frame programatically

How to Customize navigation bar in XCode5 iOS7 in AppDelegate file?

I am trying to customise the navigation bar of my iPhone app. I want to add an image in the left side of the navigation bar title.
I tried the following code from the didFinishLaunchingWithOptions of the AppDelegate.m file:
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"logo.png"]];
[myView addSubview:image];
[self.navigationController.navigationBar addSubview:myView];
self.navigationController.navigationItem.titleView=myView;
but it doesn't work. When I try it from the viewDidLoad of one of my ViewControllers it works. But i want to inherit this behaviour in all my ViewControllers
UINavigationItem has a property, titleView. You need to set that to your custom view, and then that view will replace the standard title (so you need to have your image and a label for the title in your custom view).
self.navigationItem.titleView = myView;

Solve the viewController sizing mystery! Why do elements (UIImageView and Nav bar) change size when switching viewControllers?

So this is the code for my mapView:
self.mapView = [[MKMapView alloc] init];
self.mapView.frame = CGRectMake(0, 70 , self.view.bounds.size.width,
self.view.bounds.size.height);
When I push to this view controller from one viewcontroller it looks just fine. The navigation bar and map view are all in the correct spot; however, when I tried to create a button that go directly to the map Viewcontroller from ANOTHER viewController everything changed.
The map view has shrunk and the navigation bar is missing now..? Here's the new button from the other ViewController:
UIImage* image4 = [UIImage imageNamed:#"Near_me_carousel.png"];
_mapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 18, 26, 26)];
[_mapButton setBackgroundImage:image4 forState:UIControlStateNormal];
[_mapButton addTarget:self action:#selector(MapButton)
forControlEvents:UIControlEventTouchUpInside];
[_mapButton setShowsTouchWhenHighlighted:YES];
[self.view addSubview:_mapButton];
Here's the method:
-(void) MapButton {
MapViewController *mapView = [[MapViewController alloc] init];
[self.navigationController presentViewController:mapView animated:YES completion:NULL];
}
I'm so confused as to why this is happening! Any ideas?
I don't know if this is really your problem, but here's a shot:
Inside your button method, you are calling your MapViewController modally. If the viewController itself does not have a UINavigationBar, of course it will not be displayed.
When you have a push transition, through a UINavigationController, a navigationBar is automatically added above of your view.
And here's the tricky part: when presented as a push transition, the 0 y value of the view's frame is the point just below the navigationBar. I. e., the navigationBar does not belong to your view.
And when presented through a modal transition (presentViewController:), the 0 y value is the top/left point of the window, even if you add a NavigationBar yourself.
Ilustrating:
The origin of it will be here if presented as a modal:
And here if presented if a push in a navigation stack:
Conclusion:
So, in your case, the y-value 70 in this code
self.mapView.frame = CGRectMake(0, 70 , self.view.bounds.size.width,
self.view.bounds.size.height);
will be different according to the transition style. In a modal, it will look like it's displaced 44 points to the top (size of the navigation bar)

How to also animate subview in navigation bar?

I have a subview in my navigation bar. I try to add it by this way:
UIView *customView =
[[UIView alloc] initWithFrame:
CGRectMake(0, 0, image.size.width + label.frame.size.width, 44)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[customView addSubview:imageView];
[customView addSubview:label];
[self.navigationController.navigationBar addSubview:customView];
However, when I try to push the navigation bar, the customView stays in the place, not animating following the sliding navigation bar. How can I achieve the animated subview? Is it even possible? Thanks!
you should not add subview in that way
you have tospecify your view location in the left , right or title view
self.navigationItem.titleView = YOURVIEW;
or choose another location left or right items in this way the the title view will added to the current view if you want to remove it just set it to nil in the place you want and reload it subviews again,
self.navigationItem.titleView = nil;
As you are using
[self.navigationController.navigationBar addSubview:customView];
that means the navigation bar you have create is in App delegate and is common for all the viewControllers in your project,that is why once you add a view on to it you see it on every view you have. Remove your sub-view in
-(void)viewWillDisappear:(BOOL)animated{
[Your subview remove fromSuperView];
[super viewWillDisappear:YES];
}
and add that subview in
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController.navigationBar addSubview:Your subview];
[super viewWillAppear:YES];
}
this will add the subview in that particular view only and remove it as soon as that view is popped or pushed.The code given is not correct to the syntax please give a check on that.

adjusting view after hiding navigation bar

I have an app that has both navigationbar and toolbar on display with various buttons...
I have an imageview that will act as a help overlay (like you see in many apps these days) that is semi transparent with arrows pointing to the buttons on the bars plus actual view content.
First attempt displays the imageview in the view area but leaving the bars in place...not good!
So next attempt I have included the bars as part of the imageview and add this to take up the entire screen, so far so good. I then hide the bars but oh no.....the view moves up 44 pixels (as expected)
Problem is no matter what I do I cannot get the view to move down the 44 pixels?
So the imageview displays the bars giving the illusion the overlay (imageview) is on top, but the view in between is out of whack!
Does anyone know how to resolve this?
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 750, 1024)];
iv.userInteractionEnabled = YES;
iv.image = [UIImage imageNamed:#"myimage.png"];
UIWindow *window = self.view.window;
[window addSubview:iv];

Resources