Your SlideShare is downloading. ×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

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

2,598
views

Published on

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

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

Published in: Technology, News & Politics

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,598
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. How do you invoke TouchMethods on UIScrollView in iPhone Application? 11/1/2011
  • 2. 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
  • 3. …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
  • 4. Code Snippet 11/1/2011
  • 5. Code SnippetI am covering here only the basic implementation, you can customize it todo much more stuff according to your needs. 11/1/2011
  • 6. 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
  • 7. …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
  • 8. 11/1/2011