Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I understand from the question that you know how to do the movement of the overlay, so what I meant is just that you can simply use image views big enough to make sure that their border isn't visible.</p> <p>Let's say the UIImageView would be called</p> <pre><code>UIImageView *photoImageView; </code></pre> <p>And the overlay with translucent and semi-translucent areas would be</p> <pre><code>UIImageView *imageOverlayView; </code></pre> <p>The way I see it, you need 3 different images for that imageOverlayView, depending on the device it's running on - 1 for iPad, 1 for iPhone 5 and 1 for other iPhones. Width of that image should be equal to (screen width - circle radius) * 2, height should</p> <pre><code>CGFloat circleRadius; //this would be the radius of translucent circle </code></pre> <p>So if you set the frame of the overlay properly:</p> <pre><code>CGRect imageFrame = photoImageView.frame; imageOverlayView.frame = CGRectMake(circleRadius - imageFrame.size.width/2, circleRadius - imageFrame.size.height/2, (imageFrame.size.width - circleRadius)*2, (imageFrame.size.height - circleRadius)*2); //origin is set to the middle of the image. </code></pre> <p>you'd never see the edge of the grey area. MZimmerman6's answer for implementation of the movement is good, but you should also make sure you block the circle from getting out of the borders of underlying image.</p> <pre><code>-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint new = [touch locationInView:imageOverlayView]; delX = new.x - prevPoint.x; delY = new.y - prevPoint.y; CGRect overFrame = imageOverlayView.frame; overFrame.origin.x += delX; if (overFrame.origin.x &lt; -imageFrame.size.width) { overFrame.origin.x = -imageFrame.size.width; } else if (overFrame.origin.x &gt; 0) { overFrame.origin.x = 0; } overFrame.origin.y += delY; if (overFrame.origin.y &lt; -imageFrame.size.height) { overFrame.origin.y = -imageFrame.size.height; } else if (overFrame.origin.y &gt; 0) { overFrame.origin.y = 0; } [overlayView setFrame:overFrame]; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint new = [touch locationInView:imageOverlayView]; delX = new.x - prevPoint.x; delY = new.y - prevPoint.y; CGRect overFrame = imageOverlayView.frame; overFrame.origin.x += delX; if (overFrame.origin.x &lt; -imageFrame.size.width) { overFrame.origin.x = -imageFrame.size.width; } else if (overFrame.origin.x &gt; 0) { overFrame.origin.x = 0; } overFrame.origin.y += delY; if (overFrame.origin.y &lt; -imageFrame.size.height) { overFrame.origin.y = -imageFrame.size.height; } else if (overFrame.origin.y &gt; 0) { overFrame.origin.y = 0; } [overlayView setFrame:overFrame]; } </code></pre> <p>EDIT With your pan gesture recognizer, checking if you aren't going too far needs a little change to the handlePan: method.</p> <pre><code>-(void)handlePan:(UIPanGestureRecognizer *)gesture { CGPoint newCenter = [gesture locationInView:self.view]; if (newCenter.x &lt; 50) { newCenter.x = 50; } else if (newCenter.x &gt; self.view.frame.size.width - 50) { newCenter.x = self.view.frame.size.width - 50; } if (newCenter.y &lt; 50) { newCenter.y = 50; } else if (newCenter.y &gt; self.view.frame.size.height - 50) { newCenter.y = self.view.frame.size.height - 50; } gesture.view.center = newCenter; } </code></pre> <p>If that 50 points margin is equal to circle radius, this will make sure your circle able to touch the edges of the screen, but unable to go beyond them.</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. 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