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 05-14-2009, 05:15 PM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 4
Default UIView blocking tap events?

I have created a simple UIControl subclass. In its initWithFrame method I create GradientBackgroundView (UIView subclass) and add it as a subview.

Code:
- (id)initWithFrame:(CGRect)frame skinColor:(UIColor*)Color{
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		self.skinColor = Color;

		self.backgroundColor = [UIColor clearColor];
		
		GradientBackgroundView* gbView = [[GradientBackgroundView alloc] initWithFrame:CGRectMake(4.0, 4.0, frame.size.width-8.0, frame.size.height-8.0)];
		gbView.tintColor = Color;
		gbView.userInteractionEnabled = YES;
		[self addSubview:gbView];
		[gbView release];
		
		
		UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, frame.size.height)];
		label.text = @"Cancel";
		label.textColor = [UIColor whiteColor];
		label.backgroundColor = [UIColor clearColor];
		label.numberOfLines = 0;
		[self addSubview:label];
		[label release];
		
    }
    return self;
}
The problem is my target/selector isn't invoked when I tap anywhere within gbView. Tapping within the 4 pixels boundary around it does invoke the target/selector.
It also works when I comment out gbView (leaving only the UILabel as a subview).

It looks like gbView consumes touch events somehow, i.e. blocking them before the UIControl can process them. UILabel obviously doesn't do that.
Is there anything I failed to set in gbView to pass touch events to its superview (UIControl)?
radosch is offline   Reply With Quote
Old 05-15-2009, 03:34 AM   #2 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 4
Lightbulb Fixed

Mea Culpa

I had misunderstood the meaning of userInteractionEnabled property.
It must be set to NO in gbView to let the touches pass over to the superview:

Code:
	gbView.userInteractionEnabled = NO;
Now it works great!
radosch is offline   Reply With Quote
Reply

Bookmarks

Tags
touch, uicontrol, uiview

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: 268
20 members and 248 guests
@sandris, AdamL, ADY, Dani77, diyora, FAED, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,749
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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