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.
Related
I have an NSCollectionView with a vertical NSCollectionViewFlowLayout. I display rectangular icons in it.
I also have a slider in the UI, and when that changes, I adjust the minItemSize, which I then use in collectionView:itemForRepresentedObjectAtIndexPath: to create an equally sized NSImageView to the returned NSCollectionViewItem's imageView. Then I reload the view by invoking reloadData.
After that, the view shows the icons in the new size as intended.
The problem is, provided I have more data to show than fits into the current scoll view, that when the General System Preferences are set to Show scroll bars: When scrolling, the scrollbar disappears after reloading the collection view, and trying to scroll with the trackpad leads to a bounce that's telling me that the scroll view thinks that the content is just what's visible, nothing more to scroll.
But as soon as I resize the window, which also resizes the collection view inside, the scrollbars come back.
Curiously, if the System Prefs are set to Show scroll bars: Always, then the issue does not appear and the scrolling always works, and the scrollbars always remain visible.
I've tried a lot of things to trigger the re-calculation of the scroll view, such as invalidating the layout of the collection view's layout, the scroll view itself, its content view, and also tried to set their needsLayout to true. Nothing makes this work.
Update: The potential duplicate (NSCollectionView does not scroll items past initial visible rect), neither the collectionView.setFrameSize: nor the window.setFrame: suggestions work for my case (I tried adding these line before and after reloadData).
Even if I force a resize of the window like this, it doesn't bring the scrollbars back, only a manual dragging of the window edges does:
[self.collectionView.window setFrame:NSInsetRect(self.view.window.frame, 1, 1) display:YES];
Also note that in my case, initially the scrolling works, just not after resizing and reloading.
Another finding: When I call selectItemsAtIndexPaths:scrollPosition: after reloadData, then the scrollbar comes back. But only if I pass a non-empty NSSet for the paths. And since I may not have selected any items, this isn't a permanent solution.
If no other ideas come up, I'll try to make a demo project.
I've solved it:
I had to delay the call to reloadData, e.g. by calling it from within the block code of dispatch_async(dispatch_get_main_queue(), ^{ ... });
Before the fix, I did call reloadData right from the setSliderValue: handler, which is bound to the slider's value. It appears that this didn't go well together.
I making an ipad application with screen split in half. Each side contains a container and each container holds UIView.
In the left uiView i have a uiScrollView with multiple elements (customs uiview) inside, like a grid but with scroll, and each element support tap gesture.
When i tap each element they work fine and behave like they are suppose to. lets say they do a NSLog(#"tapped!").
Problem comes when i resize either the entire view that holds the scroll view or the Container like so:
navigationVC.view.frame = CGRectMake(0,0, 338,768);
The tap stops working! But if i resize back to its original frame, tap starts working again.
navigationVC.view.frame = CGRectMake(0,0, originalWidth ,768);
I thought the problem would be the elements re-arrange when i resize the scroll view, but in fact its not.
The frame is being resized when i swipe the entire application either left or right.
EDIT:
Behaviour diagram: http://i.imgur.com/4vKpHLQ.png?1
EDIT2: didnt figure it out yet, but i see now that element bound's are changing when the frame is resized.
Got it!
Problem was that when i resized the scrollView the elements.Bounds where changing too. Then i went digging why... could only be something like a anchor... i then started to change a few properties on my XIB.
Under "Simulated Metrics", changed the "Size" drop-down from "Freeform" (add 150, 45) to "Inferred".
Forced the size on initWithCoder, compiled, and it worked.
Thanks Burhanuddin Sunelwala for trying to debug this with me.
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!
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.
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.