ClipsToBounds on a rotated superview - iphone

I am adding a subview on a rotated superview and want it to clip to the superviews bounds.
I know that the bounds are the rectangle around the rotated view and by knowing that I DON'T want to clip it to the superviews bounds but I want it to clip at the actual borders of the rotated superview.
How is that done?

Related

UIView as subview won't clip to superview

I have a superview with rounded corners.
It has a custom subview (UIView) that will cover the rounded corners of it's superview. (so the superview will look like it doesn't have rounded corners)
I tried on subview :
self.clipsToBounds=true
but it will still cover the corners of its superview.
You want the clips to bounds on your superview.

In a zoomable scrollview, how to determine the location of the content wrt the window?

I have a zoomable UIScrollView which contains a custom drawn view (two circles). When the view is zoomed, I want to know where the centres of the circles lie, wrt the App's window. Consider these steps:
The view at 1X
The view zoomed at an arbitrary level, with the pinch focused on the first circle
The view zoomed at an arbitrary level, with the pinch focused on the top right corner
What I am meaning to ask is, if I were to lay another view containing a circle on top of the scroll view such that the circle in this view is concentric (need not be of the same size) with the smaller circle in the scroll view's view, where should the centre of the new circle be located?
When using UIView's coordinate conversion methods it is not relevant that you custom view is embedded in a scroll view:
MyCustomCircleView *circleView;
CGPoint centerInLocalCoordinates = circleView.centerOfACircle;
CGPoint centerInWindowCoordinates = [circleView convertPoint:centerInLocalCoordinates
toView:nil];
Maybe window coordinates are not what you are looking for. Remember that the window's coordinate space is always in portrait orientation and with the home button at the bottom. When holding the device in landscape orientation, your coordinates are (of course) rotated.
It might be easier to convert to a superview's coordinates, for example your view controller's view's coordinate space.
Did you draw the circles? Some combination of scrollView.contentOffset, scrollView.contentSize, and scrollView.zoomScale is what you want. You can walk back the translation and scaling using those values.

How can I have pinch zoom and two-finger rotation at the same time on an UIImageView?

I have an Image View and I need to be able to pinch-zoom it, scroll it when it is zoomed and also rotate it with two-finger.
Initially I used a scrollView and added ImageView to it. but ImageView wasnt getting rotation gestures as ScrollView was intercepting them.
So I added the gesture to the ScrollView started rotating the scrollView itself.
Things work fine but rotated scrollView doesn't look good.
So I made the ScrollView get the rotation gesture but rotated the imageView in it instead of ScrollView.
But Now, the problem is If I rotate the image and then zoom and again try to rotate, previous rotation is lost and same when I rotate the previous zoom level is lost.
How should I go about it ? Is the scrollView unnecessary ?

ScrollView offsets when superview is setframe?! (iphone)

So i have a View and a scroll view inside that view. I call a
[View setFrame:CGRectMake(55,70,260,420)];
i put a
NSLog(#"%f %f",scrollview.frame.origin.x, scrollview.frame.origin.y);
before and after the setFrame and it reads 6,112 and then 6,172. 112 is correct, i have no idea where the 60 comes from. i searched 60 in my implementation file, and there is nothing that could affect the y at all. is there some rule with doing a setframe when there is a view inside that view?
Thanks
If you take a look at the UIView reference, the frame property states
frame
The frame rectangle, which describes the view’s location and size in
its superview’s coordinate system.
#property(nonatomic) CGRect frame
Discussion
This rectangle defines the size and position of the view in its
superview’s coordinate system. You use this rectangle during layout
operations to size and position the view. Setting this property
changes the point specified by the center property and the size in the
bounds rectangle accordingly. The coordinates of the frame rectangle
are always specified in points.
So i guess when you NSLog the frame for scrollview it is displayed based on the coordinates of the superview. The second NSLog shows different because the superview's coordinate system has changed.
I fixed this by making the scrollview in my code instead of doing it through the XIB. the scrollview is created after the setFrame and addSubView of the parent View

how do i get a layer's frame to automatically resize based on its superlayer's frame or its view's frame?

I'm experimenting with using cagradientlayer to draw gradients in our app instead of having a subclass of uiview manage gradients. One snafu that i've come across is that when the view that has the gradient as a sublayer of its main layer gets resized to fit the data i am trying to show, the layer doesn't resize along with it. I end up having the gradient layer end at the original frame size while my view's frame is much larger.
Is there a way to have the sublayer autoresize to fit its superlayer's frame, or the superlayer's view's frame?
Implement layoutSubviews in the subclass of your view. It gets called when the frame is resized (or when setNeedsLayout is called). Just set the layer's frame to the view's bounds:
-(void)layoutSubviews
{
someSubview.frame = self.bounds; // make the subview frame match its view
}
This will work even better
-(void)viewWillLayoutSubviews