Accessing superview ScrollView? - iphone

i added some views (every view has its own viewcontroller and nib) to an UIScrollView. How can I access the ScrollView from within the UIViews I've added?
self.view.superview doesn't get me the UIScrollView properties. I need to disable scrollEnabled from within an UIView.
Thank you!

Maybe try (UIScrollView*)(self.view.superview).property to access the property you want :-)
It should work.
But maybe with an Delegate it would be better :-p
Good Luck !

Related

accessing delaycontenttouches property of uiscrollview

Since uitableview inherits from uiscrollview, would i have access to the delayContentTouches property of UIScrollView from my table view controller? I thought I could do something like the following, but it doesn't work(self is the UITableViewController):
self.view.delayContentTouches = YES;
Thanks.
If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. This value is YES by default. You'd better tell what do you want to do?

scrollViewDidScroll not executing

I think have decent experience working with iPhone development.
as much I know.. I did set up the delegate..
I have from top to botton
UIView --> UIScrollView--> UITextView
I tried everything... to get the event scrollView to fire the scrollViewDidScroll event.
is anything wrong with the structure..
there not much of the code to post here.
what I am trying to do is.. do something when UITextView is scrolled.
Sorry did not respond... Just wanted to share in case anyone need this...
I used delegate methods of parent i.e. UIView for UIScrollView i.e. Child it worked..
It's hard to say without some code or a screenshot. Is the scroll view actually scrolling? If you set it up in Interface Builder, did you change the size of the scroll view's contentSize in code so that it can actually scroll? Maybe the text view is eating the scroll events; did you try setting the text view's delegate to see if it's firing a scrollViewDidScroll event?

Draggable UIView

I have 4 UIViews inside of a main view controller view. All I need to be able to do is drag the views around the "screen". Is UIScrollView the best option for this, or is there a simpler way?
Apple's Touches sample application contains code that does just this, so you might want to check it out.
UIScrollView should be used for scrolling, not dragging. And the 4 scroll views won't work if they're overlapped so don't even think of using UIScrollView in your case.
A dedicate UIView subclass that overrides -touches*****:withEvent: is needed. See http://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/01-Direct%20Manipulation/ for example.

Touch events aren't reaching touches methods?

I have a View Controller, and a UIImageView as a subview. That UIImageView also has a subview of that same type.
I have:
self.userInteractionEnabled = YES;
set for each. My touchesEnded code was working. Any idea what would cause this? No touches are even reaching the touches events. I don't understand?
Any help appreciated.
Thanks // :)
Sounds like you've gone all the way up the chain and checked the self.userInteractionEnabled all the way up to the top, right? Ok, now check if any view has exclusiveTouch set to YES.
Also, if you called resignFirstResponder on the parent view, instead of a UIText field, you would relinquish events.
Lastly, beginIgnoringInteractionEvents, can cause this too.
I just found this solution from saimhann2002 who was having a similar problem.
Thanks for the reply. I have been able to fix the problem now. The issue was that I was adding the subview to the MKMapView rather than the view of the ViewController. I don't know why this is an issue. If you do I would be interested to hear. Adding the view as a subview to the view of the ViewController fixed everything, with the view now accepting the touches, even when its colour is UIColor clearColor.
That works!

Touch events not working on UIViews inside UIScrollView

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.
I have enabled userInteraction on the views but it's still not working!
This must be possible and I'd be really grateful if someone could point me in the right direction!
Thanks,
Mike
Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.
I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.
Check what you are returning in scrollview delegate method view for scrollin in scroll view.
As mahboudz mentioned - check if you have any custom handler for touch event. If not, please have one. Its far more relief to do whatever you want to do with your view. Check out Apples sample app from scrollViewSuite. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!
You may find this post useful. It's an example of a pretty clean way of intercepting events.
Have touch handlers for view for which you want to receive touch events and that will work.