weird gap when using uiscrollview and uilabel - ios7

here is the problem i have a tow muti-line label with many content, so I use a scroll view to show them all
then I follow this to do the autolayout: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutbyExample/AutoLayoutbyExample.html#//apple_ref/doc/uid/TP40010853-CH5-SW2
basic idea is to make a container view outside the scroll view to make sure the labels can fill the scroll view no matter what direction it is.
here is the hierarchy and constraint:
and the portrait mode works well:
but when it change to landscape mode some wired gap pops up!
and the more text i put in the label the higher gap i got!
my question is what should i do to kill those gap?
please give me some explicit solution or just give me an example, thank you!
and i am using autolayout in ios7, so some solution without coding are preferred!

Related

Xcode UITextView Still not scrolling using storyboard

I am trying to initiate a scroll view in my UITextView and even though I seem to have selected the appropriate boxes, I can't seem to get the scrolling working. I have gone through multiple questions similar to this but none seem to have the answer.
I included an image of Xcode below:
Question 2: When I scroll down the majority of my text shows but the scrolling stops with two sentences or so left and I have to scroll down and hold it there to read. Any way I can fix this so it scrolls all the way to the bottom of the text?
Can you check the two boxes: Bounce Horizontally and Bounce Vertically and see what's happening? Sometimes your content are actually way bigger than your view, and they are touching a invisible outer box. If you can see they actually move, that means there is nothing wrong with touch or scroll, is just the view layout problem.
For the content issue, my guess is that the content size is not right, you can programmatically adjust it with textView.frame property, set it to a proper size, such as the frame of the window or the frame of the content, which are CGRect classes. Comment below to see if this can solve your second problem.
The text view will not scroll in storyboard, only the app. And the text view will scroll once the content in the text view exceeds the frame size.
If you're using iOS 7+, you can just turn on auto layout, pin each of the sides of the text view to the edge of its parent view, and it works fine without needing to do anything in code.

iOS 7 + Auto Layout: Strange UIImageView behaviour

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.

UISwitch not responsive in UIScrollView

I'v encountered strange bug, and have no idea why this happens.
I have UIScrollView, in it I have 12 views. Most of them contain UISwitch button and a label. Size of views are dynamic (depending on the lenght of label.text). Everything works and shows, except two views on the bottom. They do get shown, initialize as expected. Yet UISwitches in them do not work, clicking or touching them does not do anything. Both of them are no exception to others (all of them are copy paste). I have double checked IBOutlets, they are fine. I have suspicion something is wrong with scrollView. Maybe beyond some point it doesn't recieve inputs anymore? Eventhough I can scroll up and down and everything is shown just as expected.
Any ideas what to check ?
I have switched these two views with first ones. And more bottom views get unresponsive, like there is a line, beyond which ui is not responsive. Ideas?
You say the switch is in a view (one of 12) and that view is on the scroll view,
maybe the UISwitch is out of the view bounds? Try to set that views .clipsToBounds = YES;, can you still see the switch? If no, it means the switch is out of bounds therefor you gat no touch events. Make that view larger to fix that.
Check correctly. if the UISwitch and UIscrollview user interaction are enabled.
Check whether the UISwitch is added within the UIscrollview's frame.

Sizing and Placing a UIView from xib in Xcode 4.3

Forgive me if there is already an answer out there for this problem but I looked at them and wasn't sure about any of them. Here is my problem:
I have a xib file, which has its own view (the superview). On the superview, I have placed a Segmented Control at the top and a smaller UIView centered under the Segmented Control. Using the Autosizing Control in the story board, I was able to make the view show up where I expected. Now that I'm using a xib file in Xcode 4.3, I discovered that the Autosizing Control was not showing. I fixed that and am able to now use the Autosizing Control. However, I still cannot make the view show up where I expect.
Using Autolayout, at least my view was kind of where I want it. Unchecking Autolayout and using the Autosizing Control, it looks like the superview (or whitespace) is now getting shoved to the upper left corner next to my Segmented Control.
I'm new to XCode and the new changes are really throwing a wrench in the mix for me. Does anybody know how I can get my subview to display in the superview under my Segmented Control?
Thank you.
OK. I've learned! You really do NOT want to uncheck Autolayout. Instead keep Autolayout and learn how to deal with the new constraints. MUCH easier; MUCH better. Just become a constraints guru and the new Autolayout (default) handles everything for you (including auto rotate). SLICK BEYOND BELIEF!!!!

Resizing an NSView smaller than its subviews?

Couldn't find anything on the net about this and wondered if anyone on SO has a solution.
I have an NSView with several subviews that are centered by removing the left and right anchor points. When I resize my view, programatically or with the mouse, to a smaller width than the subviews: it pushes them off center. Has anyone come across this before and do you have a solution?
EDIT: I want to be able to resize my view to a zero width. The reason being, the view is actually part of a split view and I have hooked up a button to 'collapse' it. When it collapses all of the subviews are pushed off-center and aren't re-centered when the view is resized, effectively un-collapsing it.
I have solved my problem now and thought I would share incase anyone comes across this issue in the future.
No amount of playing with autosizing options or view layouts in Interface Builder seemed to stop my subviews from getting moved off center. I did manage to find this link here and from this page, the advice:
Springs and struts, as currently
implemented, are really no good for
anything but keeping either one or
both sides of a view "stuck" to the
nearest edge. Any sort of centering
behavior, division of gained/lost area
between multiple views, etc. has to be
done by hand.
Based on this I overrode my view's setFrame: method and manually laid out my subviews using their setFrame: method. This works great and gives me the results I'm looking for.
There is the same issue using NSSplitView, resizing here one Subview to be smaller than the Subview Subviews makes sense,e.g. having small charts in the upper subview, and an rss reader in the lower subview.
If you want to show only the rss reader in the lower subview, you can "hide" the upper subview, but after resizing the upper subview the NSImageView are not layed out the same as in the beginning. Check this nib/xCode Project and the following screenshot to see this behaviour.
Only workaroung is to override the resize function to stop getting smaller.