0

I've been trying to replicate the button on the iPhone dashboard, the Home screen. What I'm trying to achieve is the following :

  • A simple button, with an image and all its UIButton properties.
  • On top of it, a long press gesture recognizer. On the long press, the button shakes but you can still use it.

I've managed to do just all that but I'm facing the following issue, which Apple could beat, and I couldn't (yet) :

On a normal tap, the OS waits a little to make sure it's not a longpress, or a double tap, or anything I guess. It cannot know for sure it's not a special gesture until it has waited long enough. So every tap on that button is registered, but everything is delayed of about 1.5 seconds.

This is ridiculously bad user experience, but when I tap on an App in the homescreen, its' instantenous (even when the app is killed). Yet, if I longpress, it registers properly.

Mine does not. What am I overlooking here?

I have exactly this :

enter image description here

  • two UIButtons slightly overlapping each other, imagine the app icon and the "delete app" button on the corner. (blue and purple)
  • A UIView that exactly contains those two UIButtons. (green)
  • A UILongPressGestureRecognizer on that UIView (not shown)

The long gesture code is only called once the gesture has reached it's "Began" state, just like the iOS behaviour on the home screen. So pretty early in the process.

I've tried fiddling around with different properties and setups, but I can't get it to work. Has any of you achieved this? What's the proper setup?

Gil Sand
  • 5,802
  • 5
  • 36
  • 78
  • 2
    By dashboard I assume you mean the springboard. You've identified the issue of response, which is the long press recogniser on the UIButton. IMO it would be better, from a latency perspective to just use the button and no gesture. Capitalise on the events that a button brings to the table. On touchdown start a timer that will trigger the image to change and start the wobbly effect. On touch up inside or touch drag outside events invalidate the timer if the timer hasn't fired already. Use the edge insets to accomodate for the image to change with the icon badge. – Bamsworld Apr 28 '16 at 13:45

1 Answers1

1

You can use UIButton TouchDown and TouchUpInside event to achieve this.

BOOL touchInProgress;

[self.button addTarget:self action:@selector(touchStart:) forControlEvents:UIControlEventTouchDown];
[self.button addTarget:self action:@selector(touchEnd:) forControlEvents:UIControlEventTouchUpInside];

- (void)touchStart:(id)sender {
    touchInProgress=YES;
    [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(longTouch) userInfo:nil repeats:NO];
}

- (void)touchEnd:(id)sender {
    if (touchInProgress) {
        [self openIcon];
    }
    touchInProgress=NO;

}


- (void)longTouch {
    if (touchInProgress) {
        [self deleteIcon];
    }
    touchInProgress=NO;

}

- (void)openIcon {

}

- (void)deleteIcon {

}

Hope this helps.

Surya Subenthiran
  • 2,217
  • 1
  • 15
  • 22