Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-21-2009, 12:01 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 18
Default Nesting a UIPickerView in a UIScrollView...

Hey guys,

I have a scroll view set up, and inside one of it's children's children, I have a UIPickerView. So the user basically has a page they can scroll up and down on, with the picker being at the bottom. The problem I'm seeing is that the UIScrollView is 'greedy' for the swipe gesture - I can press on the UIPickerView to select things in it, but when I try a swiping motion on it to move the dial, the UIScrollView steals it.

Anyone have any recommendations to handle the swiping differently in this case? I basically want the UIPickerView to respond to swipes in it's view frame, but anywhere else, for the UIScrollView to act as it normally would.

Google produces no answers, so I'll have to rely on this forum's expertise to help me out on this one.
sbudhram is offline   Reply With Quote
Old 10-21-2009, 04:35 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 18
Default

So, a little more info, but no solution.

First, I tried subclassing the scroll view to access the touchesBegan/touchesEnded/touchesMoved methods, and just using NSLogs to make sure they were being called. Which they were! I could see that dragging/pressing was triggering the methods for my subclass.

However, if I pressed on something within my scrollview like a button, these methods were NOT called (including my picker). I'm guessing this is because they implement their own touch methods that get precedence over the scrollView. So, next I tried to subclass the picker and use the touchesBegan/Ended methods. No luck, they are not being called. And on top of that, dragging in the picker still triggers the scrollView, though it doesn't trigger the scrollView's touchesBegan/Ended methods that I implemented.

Still looking for a solution. If there are any event handling gurus out there, please speak out!

Thanks.
sbudhram is offline   Reply With Quote
Old 10-22-2009, 12:29 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 18
Default

Quote:
Originally Posted by sbudhram View Post
So, a little more info, but no solution.

First, I tried subclassing the scroll view to access the touchesBegan/touchesEnded/touchesMoved methods, and just using NSLogs to make sure they were being called. Which they were! I could see that dragging/pressing was triggering the methods for my subclass.

However, if I pressed on something within my scrollview like a button, these methods were NOT called (including my picker). I'm guessing this is because they implement their own touch methods that get precedence over the scrollView. So, next I tried to subclass the picker and use the touchesBegan/Ended methods. No luck, they are not being called. And on top of that, dragging in the picker still triggers the scrollView, though it doesn't trigger the scrollView's touchesBegan/Ended methods that I implemented.

Still looking for a solution. If there are any event handling gurus out there, please speak out!

Thanks.
I found the answer in this post:
http://www.iphonedevsdk.com/forum/ip...scrolling.html
sbudhram is offline   Reply With Quote
Old 01-03-2011, 06:17 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 1
Smile

Quote:
Originally Posted by sbudhram View Post
So, a little more info, but no solution.

First, I tried subclassing the scroll view to access the touchesBegan/touchesEnded/touchesMoved methods, and just using NSLogs to make sure they were being called. Which they were! I could see that dragging/pressing was triggering the methods for my subclass.

However, if I pressed on something within my scrollview like a button, these methods were NOT called (including my picker). I'm guessing this is because they implement their own touch methods that get precedence over the scrollView. So, next I tried to subclass the picker and use the touchesBegan/Ended methods. No luck, they are not being called. And on top of that, dragging in the picker still triggers the scrollView, though it doesn't trigger the scrollView's touchesBegan/Ended methods that I implemented.

Still looking for a solution. If there are any event handling gurus out there, please speak out!

Thanks.
Firstly I am definitely no guru, but I got this to work by creating a UIScrollView subclass and overriding the following methods

HTML Code:
@interface PickerAwareUIScrollView : UIScrollView {
}
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;
- (BOOL)touchesShouldCancelInContentView:(UIView *)view;

implementation

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
if ([view isKindOfClass:[UIPickerView class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
//|| [view isKindOfClass:[UIPicker class]]
return YES;
}
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIPickerView class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
return NO;
}
return [super touchesShouldCancelInContentView:view];
}

This cancels the touch handling in the scrollView when the event is inside the UIPickerView.
macken is offline   Reply With Quote
Old 04-25-2011, 09:36 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 1
Default

There's no need to subclass UIScrollView for this.
After researching for a while (and I've also tried the approach discussed right here), I've seen that with just two lines you'll get the perfect result:

scrollView.canCancelContentTouches = NO;
scrollView.delaysContentTouches = NO;

That's it!
ricard.perez is offline   Reply With Quote
Old 06-09-2011, 11:21 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 2
Default

Quote:
Originally Posted by ricard.perez View Post
There's no need to subclass UIScrollView for this.
After researching for a while (and I've also tried the approach discussed right here), I've seen that with just two lines you'll get the perfect result:

scrollView.canCancelContentTouches = NO;
scrollView.delaysContentTouches = NO;

That's it!

But which control is drived from UIControl that controls are not make the scroll in scrollview.
Ex. we add the UIButton in UIScrollview then set the above mentioned property. That time the scroll function not enable in the UIButton region. But the UIPickerview control swipe or scroll. So we are override the UIScrollview function "- (BOOL)touchesShouldCancelInContentViewUIView *)view". So create the custom class inherited by UIScrollview and override that function like that EX.

EX.

- (BOOL)touchesShouldCancelInContentViewUIView *)view {
if ([view isKindOfClass:[UIPickerView class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
return NO;
}
return YES;
}

Note:
-------
That method called only the Scrollview property canCancelContentTouches = YES.

So only set the property delaysContentTouches = NO. Because the canCancelContentTouches default value is YES.
ElamvazhuthiK is offline   Reply With Quote
Reply

Bookmarks

Tags
nest, picker, scroll, uipickerview, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 249
23 members and 226 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0