Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this by creating a subclass of <code>UIView</code> that is semi-transparent in the overflow region and transparent in the "crop" region and placing it over your <code>UIScrollView</code> and extending it out to cover the overflow.</p> <p>The main methods you need to implement are <code>initWithFrame</code>:</p> <pre><code>#define kIDZAlphaOverlayDefaultAlpha 0.75 - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { mAlpha = kIDZAlphaOverlayDefaultAlpha; self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:mAlpha]; self.userInteractionEnabled = NO; } return self; } </code></pre> <p>Don't miss out the <code>userInteractionEnabled = NO</code> otherwise the scroll view will not sees events.</p> <p>and <code>drawRect</code></p> <pre><code>- (void)drawRect:(CGRect)rect { CGRect apertureRect = /* your crop rect */; CGContextRef context = UIGraphicsGetCurrentContext(); /* draw the transparent rect */ CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0); CGContextSetBlendMode(context, kCGBlendModeCopy); CGContextFillRect(context, apertureRect); /* draw a white border */ CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextStrokeRect(context, apertureRect); } </code></pre> <p>The important point here is the <code>kCGBlendModeCopy</code> this allows us to draw (or cut) a transparent rectangle in a semi-transparent background.</p> <p>If you want to can make the transparent rectangle a rounded rectangle, and include a preview of the cropped image and end up with something like the screen below:</p> <p><img src="https://i.stack.imgur.com/GLLdB.png" alt="Screenshot of IDZAlphaOverlay in action"></p> <p>Sorry I can't share all the code for the screen shot. It's from a client project :-(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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