adjusting view after hiding navigation bar - ipad

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];

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

Understanding Creating a UIView programmatically with constraints tutorial?

I'm following this tutorial:
http://matthewmorey.com/creating-uiviews-programmatically-with-auto-layout/
In it (I think) he creates a little red subview and adds constraints to the red subview.
But don't you need to add constraints to the view itself (the green part)?
Lets say you wanted to make the green view always be full screen as the image shows in his tutorial. How would you do that?
The green background will automatically fill an MDMView, whatever its frame is.
This line (already in the tutorial) sets an MDMView to be the view of an MDMViewController:
self.view = [[MDMView alloc] init];
And window.rootViewController automatically fills the window with its view:
MDMViewController *rootViewController = [[MDMViewController alloc] init];
self.window.rootViewController = rootViewController;
So, no, there is nothing more you need to do in code to get the green to fill the screen.
You will, however, need to add a Retina 4 LaunchImage asset to Images.xcassets. It should be 640 x 1136. This serves to indicate that the app should support 4-inch and larger screens. Without this asset, you'll get black bars at the top and bottom on larger screens.
What it is saying is
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor greenColor];
self.view = contentView;
It means the green view is main view. You don't need to set constraints for main view. It will always be full screen.

UIImageView over Navigation bar and main screen

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];

Scroll View with Navigation Bar within another Scroll View

I have an app with three view controllers that the user can swipe between. The app loads up on the middle view controller. I am trying to create a sort of help screen, made up of a scroll view containing 3 images that the user can swipe between, as well as a navigation bar at the top to allow the user to exit the help screen. This help screen is to be displayed on top of the main scroll view, leaving 20px margin all the way around.
This is my code so far, creating the help scroll view:
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
NSArray *images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"Guide Page One.png"], nil];
self.helpScrollView.contentSize = CGSizeMake(280 * 3, 528);
self.helpScrollView.pagingEnabled = YES;
CGFloat xPos = 0.0;
for (UIImage *image in images) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(xPos, 0.0, 280, 528);
[self.scrollView addSubview:imageView];
xPos += 280;
// assuming ARC, otherwise release imageView
}
This was me trying to get it to work on the 4" screens. When I ran the simulator, the one image in the scroll view was shown on the far left of the main scroll view, and had no navigation bar.
This is how my xib is set out:
And here is the result:
The main scroll view still scrolls. I do not want this. Basically what I want is for this help scroll view to show up with my images, and allow the user to scroll through them before closing it, and continouing to the main app.
How can I do this?
Your ImageView is added on the top of layer stack when [self.scrollView addSubview:imageView] is executed, so it just hides the NavigationBar
Your helpScrollView seems to be wrong positioned. You may add constraints to properly position it.
If you want main ScrollView not to respond touches you should set mainScrollView.scrollEnabled=NO before displaying help ScrollView and when it hides set nack to YES;

Eliminating the space on the UINavigationBar between the left of the bar and the leftBarButtonItem

I currently have a button image for the leftBarButton of the UINavigationBar. Is there a way to eliminate the space between this button and the left edge of the UINavigationBar? I thought about just making a custom image for the background of the UINavigationBar, but I want to be able to use the back buttons that are generated on other screens. Ideas?
The layout logic of the navigation bar itself is going to want to try to maintain that space on the left side.
You could try specifying a custom view when setting the navigation items (UIBarButtonItem initWithCustomView:), and pass in a view with a negative x origin -- but I assume the navigation bar would ignore any such origin. (You could also try to keep a reference to that view, and move it to the left after the navigation bar finishes its layout)
Another option would be to try to create your own custom navigation bar -- possibly by putting a custom view in the center of the navigation bar, and stretching it to cover the width & height of the bar.
Try this, it works for me:
CGRect frame = self.navigationController.navigationBar.frame;
frame.origin.x = -10;
self.navigationController.navigationBar.frame = frame;
Basically, set the navigation bar x coordinate to negative not the bar item.
in ios7 you can just add a dummy barbuttonitem
for fixing left space you should add dummy as first, for right as last
example for left, you should add this after setting your original items or in viewdidload if you are setting buttons using storyboard.
NSMutableArray *buttons = [[NSMutableArray alloc] init];
UIBarButtonItem *spacerItem = [[UIBarButtonItem alloc] init];
[buttons addObject:spacerItem];
for(UIBarButtonItem *item in self.leftBarButtonItems){
[buttons addObject:item];
}
[self setLeftBarButtonItems:[NSArray arrayWithArray:buttons] animated:NO];

Resources