Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The only workaround I've found for case like that is to create an instance of a view that is transparent for touches as main view. In such case inner view will respond to touches as it fits bounds of main. In the class I've made from different examples found in the net I can control the level of "touch visibility" like so: fully visible - all of the touches end up in the view. only subviews - the view itself invisible, but subviews get their touches. fully invisible - pretty self explanatory I think :)</p> <p>I didn't try to use it with gesture recognizers, but I don't think there will be any problem, as it works perfectly with regular touches.</p> <p>The code is simple...</p> <p><strong>TransparentTouchView.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; typedef enum{ TransparencyTypeNone = 0, //act like usual uiview TransparencyTypeContent, //only content get touches TransparencyTypeFull //fully transparent for touches }TransparencyType; @interface TransparentTouchView : UIView { TransparencyType _transparencyType; } @property(nonatomic,assign)TransparencyType transparencyType; @end </code></pre> <p><strong>TransparentTouchView.m</strong></p> <pre><code>#import "TransparentTouchView.h" @implementation TransparentTouchView @synthesize transparencyType = _transparencyType; - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code self.backgroundColor = [UIColor clearColor]; } return self; } - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { // UIView will be "transparent" for touch events if we return NO switch (_transparencyType) { case TransparencyTypeContent: for(UIView* subview in self.subviews){ CGPoint p = [subview convertPoint:point fromView:self]; if([subview pointInside:p withEvent:event]){ return YES; } } return NO; break; case TransparencyTypeFull: return NO; default: break; } return YES; } @end </code></pre> <p>I believe that you can accomodate it to your needs.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload