I'm new to making apps for iOS and this problem has been bugging me for hours now.
The navigation bar in the modal popover view (on the right) doesn't properly extend to the top of the screen, like it does in other apps. I know that I could just disable Autolayout and do something like CGFloat newheight = self.InfoNavigationBar.frame.size.height + 20;
[self.InfoNavigationBar setFrame:CGRectMake(0, 0, 320, newheight)];, but I'd like to do this with Autolayout enabled, if at all possible.
Right now, the view looks like this when viewed on my iPhone:
How can I make it properly extend to the top of the screen, leaving the status bar on top of it? It'd be nice if this could be done in IB, without having to resort to doing all this in code.
(Edit: A few other iOS-related questions on SO suggest that IB and Storyboards are two different things. I don't even know which is which, take a look at the first screenshot, I'm using whatever that is.)
Apparently it's sufficient to override your UINavigationBar's positionForBar method like so: https://stackoverflow.com/a/18968920/1058399 It still feels like a dirty hack, but until there's a better way, I'll be doing that.
Edit in case any newbies like me read this:
All of this falls apart when you want your app to support landscape modes. Navigation bars are supposed to be smaller in landscape mode, which is done for you automatically if you wrap your view in a Navigation Controller. Don't just place navigation bars and expect them to "just work".
Related
I've got a strange UIImageView behaviour:
I've got a UIViewController with an embedded UIImageView and a close button. Very basic stuff, done a thousand times. I didn't use Auto Layout that much in the past, but another view controller in the same Storyboard has nearly the same config and doesn't appear as strange as this specific one.
In my Storyboard the Controller looks like that:
...and on the device it looks like that:
That image is 1024x768, so it should be filled to the bounds. Content mode in the image view is Aspect fill. When i dismiss the view, i can see that the upper part of the image view must be hidden at the top with some negative Y or something.
I need Auto Layout in this storyboard, because it's an iPhone + iPad App with both orientations.
Has someone hat a behaviour like that before?
Thank you!
Edit:
Here is the layout panel:
First, get rid of the alignment constraints, they are not needed if you're already anchoring your view to every side with a set distance.
Second, check the mode property of your UIImageView in the interface builder. If the image was not big enough and you had it set for "TOP" instead of, say, "aspect fill", you'd see something like this even though the view is actually covering the whole screen.
I'm sorry that I have to say this, but it was, as you certainly thought, my own fault.
The problem was that I made a photo with the iPad, and the iPad can be used in both orientations in this app. The photo was taken and was then used for an own view that allows the user to put annotations on the image.
The image gets then saved, and that was were the problem occured: I call
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
The landscape image was now taken into a portrait frame. After adjusting this and only allowing portrait mode, everything worked well.
Thanks anyways for your answers. And sorry for asking a question when the problem was another one and my own fault.
I'm working on an old code base written using Three20 (ack!). Now we need to be able to deploy this app to iOS7 and iOS6.
Mostly, it's working, but when the user taps and causes switching between view controllers, the navigation bar is drawn with a 44 point navigation bar during the transition animation, but when the animation finishes then it snaps to 64 points tall.
So, switch a view...smooth...butter...slam. Wash, rinse, repeat.
It's such a juddering effect when you switch from one view to another, on any iOS 7 iPhone-sized device. Interestingly, it only happens when switching from one view to another, not when switching to a new instance of the current ViewController.
I'd show code, but I'm not sure what code to show.
I'd appreciate any pointers at all (RTFM comments gladly accepted), my Google-fu has failed me this time.
View hierarchy looks something like this:
UIScreen
TTNavigatorWindow
UILayoutContainerView
UINavigationTransitionView
UIViewControllerWrapperView
UIView
TTTableView
UITableViewWrapperView
...and so on...
Is this a three20 problem where three20 assumed that Navigation Bars are always 44 points tall, but now they're not?
Is this an Interface Builder issue where the Navigation bars can only be created at 44 points, and I'm supposed to deal with this well in my code?
Is this an esoteric iOS 7 issue where it's decided that because the Navigator is at the top level, that it needs to change the height on a regular basis?
Is this a documentation issue where my (obviously meagre) powers of observation just didn't see the relevant bit in the Apple docs?
Thanks,
-Ken
First of all I would like to recommend to get rid of Three20. I know this is not very helpful for your situation, but really.
But then I would like to offer you two ideas on would could be happening:
Three20 indeed uses a hardcoded navigation bar size in various places, but I don't think this causes the problem you describe here. I may although pretty sure it causes Problem with iOS7 at other places.
From what you describe it sounds like the way iOS7 calculates the navigation bar height might be the problem. Of cause that would somehow inferrer with how three20 manages view, cause it works ok for plain UIKit. What happens if you move your whole view stack 1 px down, towards the bottom of the screen? I guess, that the navigation bar does not change it's size then. To understand that take a look at how iOS7 calculates the navigation bar height. I guess what you would like to have is the 64 px navigationbar throughout the whole animation. I'll have to figure out how to modify the frame of the view controller being presented before the animation to achieve that effect.
I hope some of this ideas can be helpful.
I have two overlapping views.
An NSTableView (the list of songs), I'll call it the table view
A layer backed NSView (for the play controls at the bottom), I'll call it the play controls view
I was using layer backed views to render the table view previously and this caused the scroll bar to render behind the play controls view, great! But as I loaded up the table view with 150+ rows of data the app slows down pretty bad as I scroll.
I changed setWantsLayer: to NO and now the table view is much snappier, great! But now the scroll bar seems to render on top of the play controls view.
Good:
Bad:
Any ideas whats going on here? (I'm a core animation rookie if you can't tell)
Why don't you resize the entire scrollview and put the play controls view below the list? It seems by your sceenshot that the play controls view is a subview of the scrollview. Is this necessary?
Resizing the entire scrollVIew could be a solution, but you might as well set the scrollIndicatorInsets:
yourTableView.scrollIndicatorInsets = NSEdgeInsetsMake(0, 0, bottomValue, 0);
Here bottomValue would be something like 50 -150, depending on the height of your view, you might have to test this, but this will do the trick.
Edit: I just see you are working on OSX, my solution works on iOS, i hope the NSEdgeInsetsMake works on Max OSX similar to UIEdgeInsetsMake does on iOS.
I need to create a scrollable composite view on iOS. That is to say, the view will contain at least one image, possibly a button, and some text (that we may wish to format with bold fonts, etc). The amount of data, and particularly the amount of text, is variable, from maybe 4 lines to maybe 100. The data is "variable" to a degree, and in particular the image and text do not come joined at the hip.
This all needs to fit in a "pane" of about 280h x 115w pixels in a portrait-only layout.
A single UITextView doesn't provide the facilities to display an image or format the text.
A UIWebView provides the ability to display the image and formatted text, but the button is a problem (not even sure if it's doable).
A UIScrollView would easily allow the image and button, and then a UIWebView could be embedded in the scroll view for the text, but then scrolling becomes a problem -- I'd like the entire view to scroll as one, without having to resize the web view to contain it's content, and without the confusion of a scrollable within a scrollable (the doc warns of "unexpected behavior").
(I'm guessing your thoughts at this point are that I want too much.)
So, any suggestions? What's the best way to get close to what I need here?
In iOS5 the UIWebView has a scrollView property, which is a normal UIScrollView. You should be able to add a UIButton as a subview of the scrollView to achieve what you want, although positioning it correctly may be a challenge. Prior to iOS5 you could cycle through the subviews of the UIWebView to find the UIScrollView with isKindOfClass...
I suggest testing with a UIWebView inside your UIScrollView. I don't see any interference in the iOS 5.0 simulator. I don't know if there are problems in iOS 4.0.
If you find that there is interference, you can prevent it by setting the web view's userInteractionEnabled property to NO, either in the nib or in code. This will prevent the web view from receiving any touches, so the user also won't be able to pinch-zoom it, follow links in it, or copy text from it.
In the web view's delegate, implement webViewDidFinishLoad: to set the web view's size and the scroll view's contentSize. For example:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGRect frame = self.webView.frame;
frame.size = [self.webView sizeThatFits:CGSizeMake(frame.size.width, HUGE_VALF)];
self.webView.frame = frame;
self.scrollView.contentSize = CGSizeMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame));
}
When I did a similar thing, I had a dozen of views which I added to the UIScrollView and then calculated the frames of all the views. Granted, it was an extremely tedious work, given that some views could get hidden under various conditions. The layout code was actually pretty simple, laying out views from top to bottom, but ugly. The upshot is that it works like a charm, fast and reliably. You can even trivially wrap it in an animation block.
I wondering how I can make a UITabBat like this:
The height of this is more than the stand UITabBar and also the icons are larger. Also the arrow on top.
I tried changing the height but it looks really bad. The icons aren't centred vertically. Also I couldn't change the background.
Thanks.
I'd suggest several things;
Check out the core animation videos from this years wwdc, you can use it to create effects like the triangle and move it back and forth. Then write your own tab bar controller class.
you could also consider a third party library like http://cocoacontrols.com/platforms/ios/controls/tabbarkit