How to autoresize UIImageView (subview) and it's image with aspect ratio? - uiimageview

I have a UIView (container view) which contains a UIImageView. When I adjust the the container view's frame (by gesture or programming), I want to autoresize the UIImageView's frame (and the image size with aspect ratio).
How should I set the autoresizingMask for those view, and the contentMode?

Related

Tableview in UIView - How to size cell and meaning of shadow

I added a tableview to a uiview in Storyboard and am having trouble getting the cell to be the right size. It is currently unusually large as a result of my trying to resize the tableview to fit the uiview. Can anyone tell me how to resize the cell (The upper handle is not visible and the dimensions are disabled in size inspector) and also why it the screen has a section in white in the middle...What is the white relative to the grey?

UIImageView in UIScrollView in UICollectionView Constraints/Auto-Layout

I'm creating a Photo Gallery using Interface Builder. I have a UICollectionView containing cells as big as the screen. A cell contains a UIScrollView with a UIImageView. that you can zoom this image:
Which constraints do I have to set for the UIImageView that:
- the image is always in the center of the scrollview, at landscape and potrait orientation
- you can zoom the image in the scrollview
I tried many options, sometimes the image is not zooming, or just a few pixels but the constraints won't allow real zooming, or somites i was able to zoom but the imageview had the wrong size and the picture was not centered

NSView with layer is drawn over all content

I have an NSView, which I change some properties to give make it a rounded rectangle, with a gray color, and add it to my view (behind everything)
float gray = 60.0f/255.0f;
NSView* background = [[NSView alloc] initWithFrame: self.iconContainer.frame];
CALayer *viewLayer = [CALayer layer];
[viewLayer setBackgroundColor:CGColorCreateGenericRGB(gray, gray,gray, 1)]; //RGB plus Alpha Channel
[viewLayer setCornerRadius:5.0f];
[background setWantsLayer:YES]; // view's backing store is using a Core Animation Layer
[background setLayer:viewLayer];
// Place view behind all other views
[self.iconContainer addSubview:background positioned:NSWindowBelow relativeTo:nil];
However no matter what I try, that particular view is drawn above everything else.
Usually, this behaviour is caused by the use of Core Animation layers on a subview, while the superview hasn't any.
Enabling Core Animation layers on the superview should fix the issue, as any subviews will then be drawn using Cora Animation layers, making the drawing process respect the order of subviews.

Draw shadow of layer-backed NSView beyond bounds

I'd like to get a custom NSShadow on a borderless NSWindow,
and since I'm also applying some animations on the window, I've set up the window's content view to be layer-backed.
When applying the NSShadow on the contentView, the shadow is clipped at the view's border:
One possibility would be to reduce contentView's rect (NSInsetRect), but then the NSWindow's resizing borders wouldn't match the window's appearance!
Is there any chance to draw the layer's shadow beyond its borders?
EDIT: The shown screenshot already has a -10 inset rect!

NSView free-angle rotation

I have NSView container (with NSImageView and some other custom subviews). How to set its rotation properly? I tried to set angle through setFrameRotation: and set rotation matrix in views layer. But in these cases subview image becomes downscaled and clipped.
Update:
If I set rotation via [myView setFrameRotation: angle]:
almost fine, except text frame (drawing via [NSString drawAtPoint:...] and rotation anchor is at left-bottom corner (I want at bottom-center, [myView setFrameOrigin:...] does nothing)
If I set rotation via myView.layer.transform = CATransform3DMakeRotation (angle, 0, 0, 1):
frame bound remains unrotated and clips subviews (but this approach is more suitable for view container)

Resources