3

I'm using an UIStepper to change a value that is displayed in a UITextField, with the option of being editable entering the value in the UITextField.

Everything works fine, but there is a undesired behavior: the UITextField can only be edited pressing the upper half of the object itself, because the touch in the lower half is swallowed by the UIStepper.

I've looking for an answer, but I haven't find any. I have some hint though.

UIStepper has 2 buttons and 1 ImageView, and the touch is detected in the entire ImageView (not visible or editable).

Any ideas?

enter image description here

jszumski
  • 7,430
  • 11
  • 40
  • 53
WokeR
  • 31
  • 1

2 Answers2

0

To fix this would most likely require subclassing. You can override pointInside:withEvent: in a UIStepper subclass and return NO unless strictly within the bounds of the stepper:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    return CGRectContainsPoint(self.bounds, point);
}
jszumski
  • 7,430
  • 11
  • 40
  • 53
0

One option is to put both the stepper and the text field inside a container view that overrides -hitTest:withEvent: such that it queries the text field before querying the stepper. If the text field says that it's hit, return a pointer to the text field. If not, check the stepper and return that if it says it's hit.

Controls sometimes pretend to be larger than they are so that they're easier to touch. Using the preceding technique should let you keep as much of the stepper's extra touchable area as possible without hindering use of the text view.

Caleb
  • 124,013
  • 19
  • 183
  • 272