0

I want to crop a portion of the viewcontroller in semicircle so that the viewcontroller behind it would be visible throught the cropped portion. Is there a way to do it using objective-c or any custom control already available.

  1. A TableviewContoller with 10 cells

  2. An ImageWiderContoller with big image and other controls

First cell of the table should have a semicircle, through which the ImageWiderContoller (which is below TableviewContoller) should be visible So Swiping left on tableview should reveil the imageWiderController

Manoj
  • 1,482
  • 2
  • 20
  • 53
  • [My Answer here](http://stackoverflow.com/questions/9711248/cut-transparent-hole-in-uiview/15810658#15810658) is probably what you are looking for – Lefteris May 18 '15 at 07:35
  • A viewController on which another viewController is pushed or presented cannot be seen under the previous one. To check just set the presented viewController's view's background to clear. – ZeMoon May 18 '15 at 07:35
  • 2
    This is not true @ZeMoon, because if the ViewController is presented modally you can set the `UIModalPresentationStyle` to `OverCurrentContext` and the previous viewController view is visible – Lefteris May 18 '15 at 07:37
  • 2
    @Lefteris Oh, this has been introduced in iOS 8. That's great to hear! – ZeMoon May 18 '15 at 07:39
  • You can use container view controller for that , instead cropping. – Mukesh May 18 '15 at 07:40

1 Answers1

1

Only way I think of doing it is having a custom UIView and set that as default view of your top most UIViewController. Inside that UIView's drawRect() method you can draw whatever shapes you want (transparent included). Like if you want to draw a transparent circle in the middle of your controller, you would do this in drawRect() of your UIView:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    [[UIColor orangeColor] setFill]; //background Fill
    CGContextFillRect(context, self.bounds);

    [[UIColor clearColor] setFill]; //circle Fill.
    CGContextFillEllipseInRect(context, (CGRect){self.center.x - 25.0f, self.center.y - 25.0f, 50.0f, 50.0f});
}

In initWithFrame: of the same UIView add this:

[self setBackgroundColor:[UIColor clearColor]];

P.S: As mentioned by @Lefteris Obviously set your UIViewController's UIModalPresentationStyle to OverCurrentContext so that it appears over the same controller.

Note: by transparent I meant the area of top controller which shows contents of the controller underneath, as you wanted.

Sabir Ali
  • 475
  • 2
  • 16
  • Thank you for your answer @Sabir Ali . I have edited my question to explain my real need – Manoj May 19 '15 at 05:08
  • 1
    You can use the same `drawRec:` appraoch by customising UITableViewCell class and putting this drawRect: function in there. Then you can use that customised `UITableViewCell` for first cell of your table and default cell for the rest. Considering your updated question It should work just fine. (PS: if I'm still getting you wrong, please share a mockup of desired Customisation and I'd be happy to help) – Sabir Ali May 19 '15 at 05:49
  • Exactly the same idea what I have implemented but I was looking for something other than this. But I would give one up for your answer though. – Manoj May 19 '15 at 11:55
  • Thanks @Manoj, if you mean you are looking for a different approach for the same result, I'd be interested in knowing your find :) – Sabir Ali May 19 '15 at 16:13
  • Ya sure @Sabir Ali I'll update once when I get new idea for my task. – Manoj May 20 '15 at 04:34