Determine if a subview is visible in a UIScrollView - iphone

I've added a view to my app, that contains a UIScrollView, with a number of UITextViews in it's content view. This works perfectly on OS 3.0 and up, but when I test it on my 2.2.1 iPod touch, there is a UITextView bug that stops any text views automatically updating their content when they are scrolled into view - so you have to send them the setNeedsDisplay message.
However, I only want to do this when they start to become visible during the scroll - how do I determine, in the UIScrollView's scrollViewDidScroll delegate method, whether a UITextView is visible in the UIScrollView's frame?
Ta.
Jools.

You have to do the calculation manually whenever the scroll view scrolls. This answer might help.

Related

Reminders.app UIScrollView scrolling explanation.

I am currently programming an application for the iPhone and I am having some issues with my horizontal (horizontal as in you scroll horizontally, not vertically) UIScrollView.
The UIScrollView's height is 260 and the width is 320. It has 2 pages and each page has a UITableView in it. The UITableView's frame is the same as the UIScrollView's frame.
The problem is that 80% of the time, the current UITableView detects the drag/swipe as a vertical scroll (but it's actually horizontal) and begins to scroll the table view vertically.
My question is the following:
Can somebody explain to me how the app Reminders does for the scrollview scrolling. If you look carefully, you can see that the scrollview handles the horizontal scrolling very well and that a horizontal scroll is handled by the scrollview (and not by the tableview like mine does). If anyone needs more explanation please leave a comment.
If I try to scroll to the left/right in the table view of Reminders, it doesn't respond to it. If I scroll in the table header view where the add button is, it scrolls without any problems. My guess is that they made the table view header a UIScrollView. Apple highly discourages the use of a table view in a scroll view (or any view that inherits from UIScrollView into a different view that inherits from UIScrollView, for that matter), so they probably wouldn't take their own advice and ignore it.

iPhone - scrollview with a textview and tableview inside

I have an interface which will have a text view and a table view below it. My current view looks like this
UIScrollView
UITextView
UITableView
Currently the TextView and TableView can scroll vertically..but what i want is the whole screen to scroll up/down. Why doesn't this work properly?
You can put a TableView inside a ScrollView, but you must resolve conflicts between touches, scrolling, and bouncing in IB or with code, and you must set the ScrollView's contentSize with code, not in IB.
If the TextView really "belongs" to the table, consider putting it in a table cell, or better, as a header, that's what they're for.

UIScrollView + UITextView resizing causes textView to scroll one line

I have a UITextView with isScrollEnabled set to FALSE. I then add it as a subview of UIScrollView. I then set the content size UIScrollView based on the size of the textView. You might wonder why I am doing this. But there is a need that it be done in this way alone. There is also a UIWebView that I add below the UITextView. I have to resize everything in textViewDidChange delegate method. Everything works fine as long as I don't rotate the view. When the device orientation changes to landscape. The first line of my UITextView scroll up and goes out of view. It never comes back on rotating over and over. My webView also behaves weirdly after rotation. It enlarges the font and messes it up. How can I avoid both these problems. Both UITextView and UIWebView are class variables that I create programmatically in viewDidLoad method of my viewController.
You should have 2 frames for each of these object and set them according to the rotation of the device.
In the device rotation delegate use an if:
- if landscape: set Landscape frames
- if portrait: set portrait frames
Hope this help

how does a subview of a scrollview know the scrollview is being scrolled

I placed a few uiimageview objects into a scrollview. How can the imageview know the scrollview is being scrolled? Since the imageview is a subview of the scrollview i can't set the scrollview delegate to the imageview.
I want to create something similar to the apps view on the iphone. Where you can hold down an app and then drag it, but if you hold and move your finger too far to the left or right the action is stopped and scrolling takes over.
"Since the imageview is a subview of the scrollview i can't set the scrollview delegate to the imageview."
And why not?
You have viewcontroller which shows the particular scrollview correct? this viewcontroller should be the delegate of the scrollview, and viewcontroller should also hold pointers (either explicitly in an array or through tag of some sort) to the uiimageviews.
Then, whenever scrollview notifies viewcontroller (through scrollviewdidscroll type of delegate method), implement your logic to update uiimageview.
To implement the exact touch sequence, you can subclass UIGestureRecognizer or write your own touch handler.. take a look at Apple's documentation on Event Handling Guide :
http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009541
It doesn't, it just draws and draws. The scrollView makes sure you only see the part you really want to see
You might want to look at three20, they have a class that is very similar to the springboard. -- Used in facebook.app
Thanks Everyone, but I found out that UIScrollView sends the touchesCancelled message to the subview when scrolling starts.

UIScrollView not scrolling when set to a tableView's tableHeaderView

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).