• Share
  • Email
  • Embed
  • Like
  • Private Content
How to invoke touch methods on UI Scroll View in iPhone app
 

How to invoke touch methods on UI Scroll View in iPhone app

on

  • 2,746 views

How do you invoke Touch Methods on UIScrollView in iPhone Application?

How do you invoke Touch Methods on UIScrollView in iPhone Application?

Statistics

Views

Total Views
2,746
Views on SlideShare
2,746
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    How to invoke touch methods on UI Scroll View in iPhone app How to invoke touch methods on UI Scroll View in iPhone app Presentation Transcript

    • How do you invoke TouchMethods on UIScrollView in iPhone Application? 11/1/2011
    • Introduction First fundamental I want to clear here is that when a touch occurs on UIScrollView in iPhone app, how do you differentiate if it was meant for scrolling or it was meant for tracking a subview? I will give you an example, suppose you have ScrollView of width say 640px and you have added 4 buttons on ScrollView as its subview. When you touch on ScrollView how does system know that the touch was meant to press buttons or it was meant to scroll the ScrollView. Let me explain the inside story, when user makes a touch on ScrollView in iPhone, a timer is started , if the timer fires without a significant change in position then ScrollView send signal to methods of touched subview in the content view. If user drags their finger far enough before timer dies then scrolling happens in ScrollView. 11/1/2011
    • …Continued Now lets come to our main point. You have embedded UIScrollView on your screen, how do you know which coordinate user touched on iPhone screen? TouchBegan, TouchMove, TouchEnded don’t work on UIScrollView. The delegate methods available for UIScrollView don’t cover this explicitly but there is a way around it. I am going to cover this. We need to create a subclass of UIScrollView. 11/1/2011
    • Code Snippet 11/1/2011
    • Code SnippetI am covering here only the basic implementation, you can customize it todo much more stuff according to your needs. 11/1/2011
    • Next step is I have created an instance of this subclass of UIScrollView in oneof my ViewController class. I can call normal UIScrollView delegate methodson it as I have done in the code above 11/1/2011
    • …Continued Now when I tap on screen with ScrollView on it, it will identify where it was a tap or it was meant to be scroll the ScrollView. If it was a tap it will access - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view in MyScrollView.m and print the coordinate of the touch location. There you go ! This is how you invoke Touch Methods on ScrollViews. 11/1/2011
    • 11/1/2011