开发者

Tap and hold: a pain in the uiBUTTon

Excuse the bad pun, I'm creating a custom tab bar in my iPhone app using UIButtons. Everything work开发者_如何学Gos beautifully except that when I tap and hold a button, it doesn't select it until I release it. It's really bugging me, because a standard UITabBarItem is selected on touch down and it just feels wrong.

I've set the IBAction to "Touch Down" and my code is pretty simple. Am I doing something wrong?

-(IBAction)tab1Pressed:(id)sender 
{
    if (self.tab1.selected == NO) {
        self.tab1.selected = YES;
        self.tab2.selected = NO;
    }
}


Got a solution! Added a UILongPressGestureRecognizer to each UIButton, instead of using IBActions. Worked like a charm!

In viewDidLoad:

tapAndHold = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAndHold)];
[tapAndHold setMinimumPressDuration:0.01];
[self.myTabBarButton addGestureRecognizer:tapAndHold];
[tapAndHold release];


You should use another event for your button. The default one is "touch up inside". The action is triggered when you release the button.

Using "touch down" should do what you want.


You can try subclassing a UIView and implementing touchesBegan:withEvent: method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜