iOS UIButton receives touch outside of frame, but not inside frame - ios

I have a subview UIbutton with frame (4,8),(13,13).
Touch A is at position (4,16) relative to superview, but gets sent to the superview, even though its within the button bounds. In window coordinates this is (49,131).
Touch B occurs one pixel left with window coordinates of (48,131) but gets sent to the subview button, even though it's out of bounds. The view reports a (-1,7) position in the UIButton.
Touch A
<UITouch: 0x7b2ddeb0> phase: Ended tap count: 1
window: <DebugWindow: 0x791357f0; baseClass = UIWindow; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x791358d0>>
view: <QueueOverlayCellView: 0x7b1ca320; frame = (2 2; 269 30); tag = 1; layer = <CALayer: 0x7b1ca3a0>>
location in window: {49, 131} previous location in window: {49, 131}
location in view: {4, 16} previous location in view: {4, 16}
Touch B
<UITouch: 0x7b442e90> phase: Ended tap count: 1
window: <DebugWindow: 0x791357f0; baseClass = UIWindow; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x791358d0>>
view: <TableButton: 0x7b1cada0; baseClass = UIButton; frame = (4 8; 13 13); opaque = NO; layer = <CALayer: 0x7b1cae40>>
location in window: {48, 130} previous location in window: {48, 130}
location in view: {-1, 7} previous location in view: {-1, 7}
The superview does not implement a custom pointInside method.
How is it that the touch out of bounds of the subview can be forwarded to the subview and the touch that is in bounds of the subview is forwarded to the superview?

Not a solution, but a workaround to my own question.
This strange behavior appears to occur with buttons that are too small, in this case its 13x13. Expanding the button size (and using contentInsent for image placement), increased the touchable area (in this case expanding it to 43 pixels wide) to about half the button.

Related

iOS touch event bug on ios 14.4

only on iPhone 12 Pro Max iOS 14.4
When I click the back button on navigationBar
the touch event pass to the bottom collectionView cell
Any idea can fix this question?
Here is the hitTest on UIWindow's log when click back button
2021-06-30 15:55:27.724531+0800 FOURTRY[36793:4319245] hit test view ---- <UIButton: 0x7fee71054bb0; frame = (0 44; 44 44); opaque = NO; layer = <CAGradientLayer: 0x600003fb9400>>
2021-06-30 15:55:27.724987+0800 FOURTRY[36793:4319245] hit test view ---- <UIButton: 0x7fee71054bb0; frame = (0 44; 44 44); opaque = NO; layer = <CAGradientLayer: 0x600003fb9400>>
2021-06-30 15:55:27.725386+0800 FOURTRY[36793:4319245] hit test view ---- <UIView: 0x7fee6f72d140; frame = (0 0; 213.5 343.051); gestureRecognizers = <NSArray: 0x60000306f4e0>; layer = <CAGradientLayer: 0x600003fbd540>>
2021-06-30 15:55:27.725702+0800 FOURTRY[36793:4319245] hit test view ---- <UIView: 0x7fee6f72d140; frame = (0 0; 213.5 343.051); gestureRecognizers = <NSArray: 0x60000306f4e0>; layer = <CAGradientLayer: 0x600003fbd540>>
UIView: 0x7fee6f72d140 is the collectionView cell, Why happen this?

UIScrollView zooming on incorrect point

I have a UIScrollView with an image, and the image is in a container view. The view hierarchy looks like this:
UIScrollView
UIView
UIImageView
Panning works fine, but when I use the pinch gesture to zoom, the image changes size, but doesn't move relative to the origin, so the point centred underneath the two fingers moves as the gesture progresses. This makes it very difficult to zoom in on a particular point, since it's sliding away as you're zooming.
Description of the views involved:
<MyApp.MyView: 0x7ff6fd827e00; baseClass = UIScrollView; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x61800004a4d0>; layer = <CALayer: 0x618000023420>; contentOffset: {684, 487.5}; contentSize: {1731.4584832023011, 1154.3056554682007}>
<UIView: 0x7ff6fbe0c4d0; frame = (0 0; 1728 1152); transform = [2.2028669620902912, 0, 0, 2.2028669620902912, 0, 0]; layer = <CALayer: 0x6180000234c0>>
<UIImageView: 0x7ff6fbe09cd0; frame = (0 0; 1728 1152); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x618000023340>>
I have the UIImageView inside the UIView wrapper because I will have other views overlaid on the image which need to zoom/scale with the image.
There's very little of my own code running during the zoom. The UIScrollViewDelegate returns the UIView (the parent of the UIImageView), and configure the scroll view:
minimumZoomScale = 0.2
maximumZoomScale = 3.0
contentSize = image.size
Well, I've made a simple project that use your structure of views. And I didn't face with the problems. Possibly, you should check this things:are auto layout constraints setting right way is your parent view zooming correctly is mode of UIImageView fitting your needs Hope this may help

2 UIPageViewControllers gestures conflict

I've got 2 UIPageViewControllers one inside other, both with horizontal scroll. One fullscreen, containing all the user info, another - photo gallery for this user. Behavior: when i swipe all the user photos, it swipes the fullscreen. But sometimes, i can't swipe photos, seems like this gesture is blocked, and it swipes only the first pager. But it unblocks when i make back swipe gesture. Here is a video, of what i'm talking about: https://youtu.be/Hr7tDKNv15A Help me find error causing it, at now I can't imagine how i need to debug that.
Overrided hitTest of container view, which stores inner pager:
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
if pointInside(point, withEvent: event) {
print("Inside")
print("Self view:\(self)")
print("Self subviewsview:\(self.subviews)")
print("Self subviewsview of subview:\(self.subviews[0].subviews)")
return self.subviews[0].subviews[0]
} else {
print("Outside")
return nil
}
}
That's my output, when i touch photos:
Inside
Self view:<armeniaApp.debugGesture: 0x7f7f8be46e60; frame = (0 0; 400 400); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7f7f8be1e7c0>>
Self subviewsview:[<_UIPageViewControllerContentView: 0x7f7f8be920a0; frame = (0 0; 400 400); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x7f7f89ff1e00>>]
Self subviewsview of subview:[<_UIQueuingScrollView: 0x7f7f8a836e00; frame = (0 0; 400 400); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7f7f8be81db0>; layer = <CALayer: 0x7f7f8be522b0>; contentOffset: {400, 0}; contentSize: {1200, 400}>]
So the gesture that i need stores in UIQueuingScrollView but what i need to do next? return self.subviews[0].subviews[0] doesn't help
I'd suggest taking a look at requireGestureRecognizerToFail: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/#//apple_ref/occ/instm/UIGestureRecognizer/requireGestureRecognizerToFail:
It seems like UIKit is getting confused as to which page controller to pass the gestures on to as they will both be listening for the same thing.
I'd imagine you want the outer page view controller's gesture recognisers (accessible as an array property: self.pageViewController.gestureRecognizers) to require the gesture recognisers of the inner page view controller to fail. That way the swipe between photos will take precedence, but if there are no further photos to swipe to, you should be able to swipe between profiles.

Hierarchy is different in storyboard and when debugged while app is running

I have used auto-layout and scrollview. I have created hierarchy in storyboard which looks as shown below :
Basically view has scrollview inside it and scrollview has another subview view1 inside it. Rest of the views are under view1.
While debugging one issue I am facing I show that self.scrollView.subviews prints 3 views. Out of them 2 are ImageViews. And those are not subview of scrollview as per the hierarchy in storyboard.
(lldb) po self.scrollView.subviews
<__NSArrayM 0xb66fe80>(
<UIView: 0xb74b110; frame = (0 0; 320 3240); autoresize = RM+BM; layer = <CALayer: 0xb74b170>>,
<UIImageView: 0xb7e61c0; frame = (313 476; 7 3); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0xb7e62a0>>,
<UIImageView: 0xb7e6350; frame = (314.5 3091.5; 3.5 36); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0xb7e6430>>
)
What can be wrong here? Ask for any detail you need.
The UIView on your console is this view
the 2 UIImageView's are the scroll indicators
And one cool thing to debug view hierarchy is recursiveDescription.
po [self.view recursiveDescription]

Frame shifted incorrectly with Autoresizing in iOS7

I'm having an issue with a view using autosizing resizing improperly in iOS7 (but fine in 6). The view initially renders as I'd expect, then I push another view onto the stack. Once I pop back to the original view, a subview that should be anchored on the right sizes itself too large and of the bounds of the superview.
It's a fairly simple view, created in a Storyboard, that includes the following hierarchy:
Scrollview -> View ->ImageView
It uses autosizing masks, which frankly was done because I had issues using autolayout inside the scrollview in this case (don't want to get into that here). The mask for the ImageView is pretty simple:
-
|
_
|-|<->|-|
-
|
-
On initial load, the X coord and width are as follows:
UIScrollView: frame = (0 64; 320 455); clipsToBounds = YES; autoresize
= W+H;
UIView: frame = (0 0; 320 568); autoresize = W+BM
UIImageView: frame = (20 110; 280 50); clipsToBounds = YES; opaque =
NO; autoresize = W;
On subsequent load, it appears as follows
UIScrollView: frame = (0 64; 320 455); clipsToBounds = YES; autoresize
= W+H
UIView: frame = (0 0; 320 568); autoresize = W+BM
UIImageView: frame = (20 160; 320 50); clipsToBounds = YES; opaque
= NO; autoresize = W
The notable difference being, as bolded, the width of the ImageView frame increases to 320, which is the size of it's bounds. Since it is still offset by 20, it ends up running off the screen. Obviously, I would expect it to stay at 280, as it does when this same thing is run in iOS6.
I don't manipulate the view in any way in code, so this should all be tied the autolayout masks. I cannot find anything about others having similar issues.
--

Resources