开发者

reasons why a UIButton with image doesn't always fire?

开发者 https://www.devze.com 2023-03-13 11:02 出处:网络
I\'m at a loss.. I have a UIButton which almost works well. 98% of the time it fires the selector when pressed.

I'm at a loss.. I have a UIButton which almost works well. 98% of the time it fires the selector when pressed. 2% of the time it seems to get stuck for a while... about 5 seconds not accepting touches, then it magically starts working again. This is how I declare it.. In the init of the parent frame:

CGRect frame                    = CGRectMake(0, 0, 320, VIEW_FRAME_HEIGHT);
self.frame                      = frame;    
self.autoresizingMask           = UIViewAutoresizingFlexibleWidth;      
self.backgroundColor            = [UIColor colorWithRed:0 green:0 blue:0 alpha:BACKGROUND_ALPHA];


selectedLocationIndex = 0;

// create next/previous buttons
[nextButton release];
UIImage *nextImage      = [IMagesClass getImage:IMAGE_KEY_NEXT];    
CGRect nextFrame = CGRectMake(0, 0, nextImage.size.width + BUTTON_PADDING, nextImage.size.height + BUTTON_PADDING);
nextButton = [[UIButton alloc] initWithFrame:nextFrame];
nextButton.backgroundColor = [UIColor greenColor];
[nextButt开发者_Go百科on setImage:nextImage forState:UIControlStateNormal];
[nextButton addTarget:delegate action:@selector(onChangeLocation:) forControlEvents:UIControlEventTouchUpInside];
nextButton.showsTouchWhenHighlighted = YES;
nextButton.tag = NEXT_LOCATION;
nextButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
nextButton.center = CGPointMake(self.frame.size.width - (BUTTON_INSET + (nextButton.frame.size.width / 2.0)), VIEW_FRAME_HEIGHT / 2.0);
[self addSubview:nextButton];

I appreciate any help! Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消