How to draw UIBezier path for Custom views? - ios

I have a UIView which contains a stack of subviews. I want to draw bezier path on the super view. The angle of subviews is dynamic. Can somebody tell me how to achieve this?

Related

How can I animate a tile in a UIView

I need to create an animated chevron effect using the bitmap tile below. I am hoping that a UIView with a pattern fill will be sufficient, but I need to be able to animate the origin of the pattern over time, and I can't see that this is possible.
I think this is possible with Quartz, or CoreGraphics at the low level. What would be the best way to do this, and can you provide some example code in Swift that demonstrates the solution?
I would add the image as contents of multiple sublayers (CALayer instances) aligned one below the other and animate those sublayers y position.
The main layer would clip its sublayers on the border and sublayers that go offscreen would move to the bottom to be reused, similarly to how UITableView reuses its cells.
You might also want to look at CADisplayLink to have better control of the rendering.

Drawing beyond a UIView's bounds

I'm trying to draw a complex border around a UIView in it's drawRect method using core graphics. The border is being clipped because it's outside of the view's bounds. Is there any way to prevent this clipping? Setting clipsToBounds to NO doesn't work.
drawRect: gives you a CGRect. This defines the area in which you can draw. As it stands, you cannot draw outside this area.
You'd have to look into a different solution to your problem. I'd suggest CALayers, or a subview/superview hierarchy, perhaps a border view and a content view. But don't try doing that in drawRect:, unless you can get the desired results while keeping within the area specified by drawRect:.

Masking a view so it only appears outside of a closed Bezier Path

I have a closed Bezier Path. It is currently masking a UIView in the normal way, meaning that only the parts of the view that are within the bounds of the path are visible. I have now decided on an aesthetic feature that would be very easy to implement if there were a way to anti-mask with the same bezier path. What I mean is that now I would like a different UIView, which is currently totally visible outside of the path, to be cut off as soon as it intersects with the Bezier Path. Is there a way to set the mask of this other UIView to be the inverse of the Bezier Path?
lets say the instance of view which has to be masked be maskedView(mview -red color).
And lets say there is a backgroundView(bview - green) which is below this maskedView.
If you just mask the view, then the area inside of path of maskedView will be visible and the area outside of path will be filled with backGroundView.
So, we say mView is masked while bview is in the background.Another way of saying is that bView is front and is anti-masked while mview is down of bView. Eventhough we apply mask to mView, the screen appears to us that bView is anti - masked.
So, we create such an illusion for anti-masking a view.
programatic explanation:
view1 - anti mask this view (green color view of image)
view2 - backgroundView (red color view of image)
*[self.view addSubview:view1];
*[self.view insertSubview:view2 aboveSubview:view1];
//now view2 is top of view1
*apply bezier path to view2 not view1.
Hope this helps.

Resizing a rectangle drawn in drawRect

I have two UIViews. My aim is to draw the smallest rectangle which contains both these UIViews. I thought to draw a rectangle using the frame which I'll get out of
CGRectUnion(view1.frame, view2.frame);
But when I move any of the two UIViews, I need to update the frame of the outlining rectangle.
I thought I could do this by :
1) Resizing the previously drawn rectangle.
(or)
2) Deleting the previously drawn rectangle and drawing a new one.
The problem is that, I don't know how to get the instance of the previously drawn rectangle. So, I don't know how to update or delete it..
Can any of you guys help?
Is there any other solution to this problem?
Perhaps you can declare the following in your .h file:
CGRect *transformingRect;
Doing so should retain the rectangle and its properties so long as whatever view controller this is in is visible and loaded. This way you can have a method that resizes the same drawn rect. You would simply call this whenever you need to resize it.
-(void)resizeRect {
transformingRect = CGRectUnion(view1.frame, view2.frame);
}

How to make irregular shaped UIScrollView?

I want to make irregular shaped UIScrollView(using CGPath or UIBezierPath).
The contents will be scrollable and zoomable. And scroll actions will be accepted only in these areas, not rectangular area. Any ideas?
Your could use a CAShapedLayer with a path to create a clipping path and apply this to the Scrollview's layer's mask. Use the same path in the view's hitTest:withEvent: to decide, if the UIView should response to a touch or not.

Resources