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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 09-10-2010, 05:37 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 16
el3ktro is on a distinguished road
Default UISwitch stops working when using UIGestureRecognizer

Hi, I have a full-screen UIView and a UISwitch as subview. I'm implementing a UIGestureRecognizer on the UIView. The gesture recognizer works fine, but when I enable it, the UISwitch no longer works by tapping it - I have to explicitely slide my finger over it to toggle it. I rather want that the UIGestureRecognizer works only on the parent UIView, but not on it's subviews. When I don't use gesture recognizers but the touchesBegan/touchesEnded methods instead, the UISwitch is working as intended. Is there any way around this?


Code in UIView:

Code:
- (id)initWithFrame:(CGRect)frame andPlayerName:(NSString*)playerName {
    if ((self = [super initWithFrame:frame])) {
self.backgroundColor = [UIColor redColor];
self.opaque = NO;
myPlayerName = playerName;
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
nameLabel.text = myPlayerName;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.opaque = NO;
nameSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 50, 50, 20)];
[nameSwitch addTarget:self action:@selector(toggleNameLabelVisibility) forControlEvents:UIControlEventValueChanged];
nameSwitch.on = TRUE;
[self addSubview:nameLabel];
[self addSubview:nameSwitch];
[nameLabel release];
[nameSwitch release];
[self createGestureRecognizers];
}
   
return self;
}


- (void)createGestureRecognizers {
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[self addGestureRecognizer:singleTap];
[singleTap release];
}


- (void)handleSingleTap:(UIGestureRecognizer*)sender {
CGPoint location = [sender locationInView:self];
NSLog(@"%f, %f", location.x/768, location.y/512);
}
el3ktro is offline   Reply With Quote
Old 05-02-2012, 09:42 PM   #2 (permalink)
[[Brain alloc]init];
 
fhsjaagshs's Avatar
 
Join Date: Aug 2011
Location: New Jersey
Age: 15
Posts: 92
fhsjaagshs is on a distinguished road
Default

I am having the same problem as you!! I have UIButtons on a subview of a UITableViewCell. Then I have a swipe gesture recognizer for the UITableView that controls the UITableViewCell. Its a pull-to-reveal thing.



If you find any solution, let me know.
fhsjaagshs is offline   Reply With Quote
Old 05-02-2012, 10:22 PM   #3 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Make yourself the delegate of the UITapGestureRecognizer. Implement gestureRecognizer:shouldReceiveTouch:. Check whether the view property on the touch object passed in is equal to self.view. If it is, return yes, if not, no.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Reply

Bookmarks

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: 339
13 members and 326 guests
bignoggins, carlandrews, cgokey, flamingliquid, givensur, hzwegjxg, ilmman, jenniead38, linkmx, mraalex, PixelInteractive, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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