UIScrollView not scrolling when set to a tableView's tableHeaderView - iphone

I'm having difficulty scrolling a UIScrollView instance in my UITableView when I set it as a tableHeaderView.
It still responds to touch events it appears, but doesn't wish to scroll horizontally. I've tried explicitly setting to setUserInteractionEnabled:YES without much luck.
Is there something in particular I need to do to get scrolling working when this is set as a tableHeaderView?
Thanks.

You probably need to check your scrollView.contentSize, ensure scrollView.contentSize.width > bound width.

This embeds a UIScrollView inside a UIScrollView (since UITableView is a UIScrollView). You probably want to set the tableview's canCancelContentTouches to NO so it doesn't cancel your UIScrollView's touches. That may create some problems if your UITableView needs to scroll vertically.
If that is your issue, subclass UITableView to overload touchesShouldCancelInContentView: so that this does not return YES for horizontal drags (or perhaps for touches in the header).

Related

iOS UIScrollView in UIWindow

I currently am making an iOS project in which I have a UIScrollView as a direct subview of a UIWindow (using [window addSubview:scrollView];). The window's frame and its content are being set properly, and the contentSize is set to be bigger than the window's frame. When I try to scroll the UIScrollView, it doesn't scroll at all. Both scrollEnabled and pagingEnabled are set to YES, but the scrollview doesn't scroll, which leads me to believe that the touch/scroll events are not even being received by the scroll view. The window has a UITapGestureRecognizer added to it if it makes any difference. Do I need to somehow forward the swipe events to the UIScrollView, or is there a different reason that it's not scrolling?
EDIT: Here's some code.
float count=ceil([self.msgArray count]/2); //msgArray has length of 3+, NSLog()'d and confirmed.
float contentHeight=97.5 * count;
[dataScrollView setContentSize:CGSizeMake(320,contentHeight)];
dataScrollView.userInteractionEnabled=YES;
dataScrollView.pagingEnabled=YES;
dataScrollView.scrollEnabled=YES;
dataScrollView.clipsToBounds=YES; //Have also tried with this set to NO, or not set at all.
//Add subviews to dataScrollView.
EDIT: Here's some more info.
contentHeight is 195.00 when logged. I've removed the delegate method and I am back to using direct subviews of the scroll view. The window's height is 97.50.
EDIT: I've also removed the UITapGestureRecognizer from the UIWindow, but the scrollview still doesn't scroll.
Ah, the UITapGestureRecognizer! This might be a bug that took me hours to figure out in my own project. Is its cancelsTouchesInView property set to NO like it should be? (YES is the default... It can really throw you off if you're not expecting it.)
Just log the scrollview bounds width/height. The content height you are setting should be greater than the scrollview height. If its more then the scroll view automatically enables its scrolling.

How to scroll a simple UIView (not uitableview) in iphone?

I have added some uitextview in my uiviewcontroller.But some of the textViews are not seen as view is small compared to the number of textViews. So I want scroll it, so that i can see the other textViews also. One more thing-- when i want to type something in the lower textView then it hides because of the iphone keyboard.If somebody knows about it, please give me with the solution.Thanks a lot.
Add UIScrollView in self.view. Now add all subviews to UIScrollView.
Provide contentSize of UIScrollView in width and height.
if heigth > 460 it will scroll vertically
if weight > 320 it will scroll horizontally
If any condition doesnot matches then u will not be able to scroll
You simply have to use UIScrollView.Instead of adding all of your subviews(in your case multiple UITextViews) in the main view, just add a srollView in your view and then add all subviews in that scrollView.UIView doesn't have the property to scroll.And don't forget to change the contentSize property of scrollView.
You must implement a UIScrollView. This is a fundamental class when it comes to iPhone development (and just Apple development in general) and it should be mastered before you continue onto more advanced topics. Here is the documentation for the class :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

Preventing ScrollView from scrolling in certain area?

I hope you can help me...
I have a scrollview (UIScrollview) that contains a contentView (UiView).
Inside the contentview I have a Horizontal slider. My problem is that if the user swipes just next to the slider, trying to hit the slider, the scrollview scrolls. I would like to enlarge the area of the slider if possible, or just disable scrolling for a certain part of the scroll view.
Is this possible, and if yes, how?
Thanks...
You need to look at the following properties for customizing the look of a scroll view:
indicatorStyle
scrollIndicatorInsets
Or if this isn't to your taste: You could subclass UIScrollView and when the custom slider receives touches, read them in transform them and call setContentOffset on the UIScrollView. In my opinion that seems like a big task for very little reward and I'd just stick with the default behaviour/look.

Prevent subview from scrolling in a UIScrollView

I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal).
The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls.
I can't seem to make my subview stay put! How can I accomplish this?
The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews.
Add the view that you want not to move as a sibling view of the scroll view on top of the scroll view instead of as a subview.
You can set it's property called userInteractionEnabled to NO

Second UIScrollView responding when using a UIScrollView

This is more of a check as I believe this is right but its a lot of work if I'm wrong.
I want to basically achieve fixed positioning with a scrollView. I want to have a list along the top that is always visible, scrolls horizontal only and then a scrollview beneath that to move around the information which scrolls both vertically and horizontally.
I figure I need to subclass UIScrollView and overwrite touchesBegan, touchesMoved and touchesEnded to send the touch to both UIScrollViews.
Is this right or off track?
Cheers
Overriding the touch events on a scroll view is probably not what you want to do. Instead you can simply use a single scroll view, and then in the parent view's -layoutSubviews or in the scroll view's delegate methods you can move the list so it's always at the same vertical position (use the scroll view's contentOffset property to determine where that should be). Both the delegate method and -layoutSubviews is called before the drawing actually occurs after the scroll view scrolls, so by always repositioning your view where you want it to be, it will appear to remain fixed to the user.