RemoveFromSuperview not working on iAd Banner - ios

adBannerView.removeFromSuperview() isn't working on my scene - when you press a button the ad should disappear but it doesn't.
if i print the adBannerView from inside the button pressed block it prints
<ADBannerView: 0x15e54b910; frame = (0 0; 414 50); clipsToBounds = YES; hidden = YES; gestureRecognizers = <NSArray: 0x17024cfc0>; layer = <CALayer: 0x170234640>>
so hidden = yes, but it is still shown?

Be sure that you're triggering the method on the main thread, try this:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
adBannerView.removeFromSuperview()
})

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?

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.

ScrollView and subviews don't match between code and Storyboards?

I have created a UIScrollView in my Storyboards file, and properly connected it to my controller IBOutlet attribute. Here is what it looks like in Storyboards:
UIScrollView
UIView 1
UIView 2
UIView 3
Constraints
...
This is the code I am running on viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"COUNT: %d", [self.scrollView subviews].count);
for(UIView *v in [self.scrollView subviews]) {
NSLog(#"View: %#", v);
}
}
I was, therefore, expecting to see my 3 views listed in my console log. However, it is printing something totally unrelated (2 UIImageViews?):
2014-09-17 13:06:33.155 Project[6333:652705] COUNT: 2
2014-09-17 13:06:33.156 Project[6333:652705] View: <UIImageView: 0x7b094460; frame = (233 124.5; 7 3.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x7b0947c0>>
2014-09-17 13:06:33.156 Project[6333:652705] View: <UIImageView: 0x7b094fb0; frame = (236.5 121; 3.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x7b095080>>
I may be clearly doing something wrong here, but is there some sort of cache in Interface Builder or the Outlet connection itself?
The image views are the scrollers at the edge of the scroll view. When viewDidLoad is called the view hierarchy hasn't been fully installed yet. Move your code into the awakeFromNib method instead (and watch out for the image views - generally don't rely on the subviews, keep explicit references to the views you want to access).

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]

RootView Controller are shown shorty when state restorating

I use the state restoration offered by the SDK.
I load all my view controllers from the storyboard. The initial view controller shows another view controller modally. Both have a restoration identifier.
The restoration works fine BUT: When I am in the modally presented view controller and press home (save the state). Then reopen the app and state restoration starts the following happens:
For a split second I see the initial view controller and then the screen changes to the modally presented controller which I actually want to see.
Why is this happening? The snapshot in the caches directory does show the correct screen (from the presented view controller).
You can reproduce the issue with this project. Add a breakpoint in the initial view controller's viewDidAppear method and when restoring state, you will see initial view controller's view in the screen and in view hierarchy:
(lldb) po [[UIWindow keyWindow] recursiveDescription]
<UIWindow: 0x155607f0; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x15560d20>; layer = <UIWindowLayer: 0x1555f4f0>>
| <UIView: 0x15542ad0; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x15542a70>>
| | <UIButton: 0x155432d0; frame = (137 269; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15543b30>>
| | | <UIButtonLabel: 0x15663dd0; frame = (0 6; 46 18); text = 'Button'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1566da20>>
| | <_UILayoutGuide: 0x15542b60; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x15542fe0>>
| | <_UILayoutGuide: 0x15541060; frame = (0 480; 0 0); hidden = YES; layer = <CALayer: 0x155410d0>>
If you check view controller hierarchy, modally presented view controller is not in initial view controller presented property:
(lldb) po [[[UIWindow keyWindow] rootViewController] presentedViewController]
nil
and breakpoint is after (theoretically) state restoration. But later it will be set correctly.
That issue seems to happen when working with storyboards where you let the framework call [window makeKeyAndVisible] for you and it is happening after restoration.
If you add next line to application:willFinishLaunchingWithOptions:
[self.window makeKeyAndVisible];
it will fix it.

Resources