As shown in below image, part in the red rectangle in buttons near the screen edge cannot respond to tap normally. I've heard some mechanism in iOS that can disable touched near the edge for user experience consideration. So how to disable this mechanism? Or how to make buttons near the edge work normally.
I tried UIButton: Making the hit area larger than the default hit area. It works for "Center" button in the image but not for "Edge" button.
Thank you!
Asked
Active
Viewed 971 times
3
3 Answers
2
This problem is occurred by system-wide gesture recognization.
Left edge is occupied by system to provide 3d-touch app switcher, top and bottom are used by control center and notification center.
You can override it likes below:
-(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
return UIRectEdgeAll;
}

jeeeyul
- 3,727
- 1
- 24
- 37
0
The problem may be due to frame of button. Make sure that the edge buttons frame is inside the bounds of its superview.
if you want the button in right edge of screen then set the frame for button some thing like,
CGSize deviceMainScreenSize = [[UIScreen mainScreen] bounds].size;
UIButton *edgeButton = nil;//initialize edge button
CGFloat edgeButtonWidth = 60;
[edgeButton setFrame:CGRectMake((deviceMainScreenSize.width-edgeButtonWidth), 200, edgeButtonWidth, 30)];

Saif
- 2,678
- 2
- 22
- 38
0
Add this in viewDidAppear
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let window = view.window,
let recognizers = window.gestureRecognizers {
recognizers.forEach { r in
r.delaysTouchesBegan = false
r.cancelsTouchesInView = false
r.isEnabled = false
}
}
}

Mina Makar
- 51
- 10