UIImageView "squashed" after CGAffineTransformMakeRotation - iphone

I have a UIImageView which is inside another UIView.
I rotate the UIImageView with something like:
object.transform=CGAffineTransformMakeRotation(angle)
When the outer UIView is not rotated, and can use CGAffineTransformMakeRotation to rotate the UIImageView, and it works properly.
However, When the outer UIView is rotated, and I then rotate the UIImageView (non-zero "angle" above) - the UIImageView appears "squashed" or "flattened".
This seems to constantly get worse and worse as it is rotated through different angles.
Why is this happening? Is the outer UIView modifying the transformation matrix that I am then modifying again by explicity setting it?
How can I rotate a UIImageView within a rotated UIView and have it just rotate correctly?

Maybe your UIIamgeView is autoresized by it's superview.
You can try disable the autoresizing ability by setting:
imageView.autoresizingMask = UIViewAutoresizingNone;
or if you just do not want iOS to automatically change the size of your imageView but still want it to automatically set the position for you, you can call:
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;
Tell me if you still have problem.

Antialiasing is the process whereby a view’s edges are blended with the colors of the layer below it. Antialiasing for view edges can be enabled systemwide by setting the UIViewEdgeAntialiasing flag in your app’s info.plist, but as the documentation warns, this can have a negative impact on performance (because it requires Core Animation to sample pixels from the render buffer beneath your layer in order to calculate the blending).
Renders with edge antialisasing = YES

Related

how do I scale the image in a UIImageView when in "centre" mode? (change frame doesn't work)

Question - How do I scale the image in a UIImageView when in "centre" mode? (change frame doesn't work) I should clarify in that I would like to be able to do this programmatically.
I can scale the UIImageView by changing it's frame to something smaller but on and same center, and this works (I put a border on view to check), however the actual image in the UIImageView doesn't change. Remember the UIImageView mode has got to be "Centered".
Background: the reason I ask is because I have some images I want to scale between orientation changes, and they need to be centered, however their views can NOT have a "aspect fit" mode as some of the views are being rotated over time using a transformation, and having them auto-scale as orientation changes occur as they rotate won't work well.
Try to set the contentScaleFactor (available in iOS 4.0) or the transform property:
imageView.contentScaleFactor = scale;
imageView.transform = CGAffineTransformMakeScale(scale,scale);

How to rotate a UIImageView?

It's quite frustrating not to be able to do such a simple task: I have an "app" with a single viewcontroller, and in it a single UIImageView, that's initialized to a specific image at potrtait mode.
Now when the iPhone gets roteated to landscape mode and the shouldAutorotateToInterfaceOrientation event fires, at which I return YES, my resulting UIImageView looks totally screwed up: either the image is stretched so to fill landscape mode frame (which looks ridiculuous of course) or the top and bottom of the image are cropped.
How can I have my UIImageview and the contained image handle the device rotation gracefully, and display normal looking image at landscape mode as well?
Set the image view's parent UIView autoresizesSubviews to YES.
Also set the autoresizingMask of the image view to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
you also want to look into your UIImageView's contentMode. aspectFill and aspectFit behave very differently.
You can always subclass UIView and override the layoutSubviews method to manually lay out your subviews. The transition to landscape will still be animated, and you can do whatever you want with the subviews.

Why is a SubView resizing after InterfaceRotation?

I'm adding a subview to the UiView of my mainviewcontroller, that is presented in a similar way as a UIModalViewController with the Formsheet-style. (so it doesn't fill teh whole screen)
No if the device rotates the subview somehow gets resized to fill the whole mainview...
Even if I manually set:
subViewCtrl.view.autoresizingMask = UIViewAutoresizingNone;
it still autoresizes.
Why can't it simple stay in the middle as any other subview would?
Ok, I figured it out myself.
I accidentally did
[self.view.superview addSubview:rowCtrl.view];
so I changed this too
[self.view addSubview:rowCtrl.view];
and it worked as intended. Thanks anyway!
Of course, then one also has to set
rowCtrl.view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
otherwise it doesn't get centered properly when the interface rotates.
Is the view resizing, or is the view staying the same size while the dimensions of the screen change? You may want UIViewAutoresizingFlexibleWidth and/or UIViewResizingFlexibleHeight. If you use those values then your subview will resize to remain a constant distance from the edges of the screen; your view will change sizes, but remain centered.

Rotating the uiview without IB

In my app all my controls are created in code. I have not used IB for controls. now i want to rotate the view to landscape mode. I know I have to use the shouldAutorotate method for this purpose.
But since I have not used IB, how can I resize the controls when they are in landscape mode? How can I position them correctly using code only?
In most cases you can get views to resize themselves appropriately just by setting their autoresizingMask property to some combination of:
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleBottomMargin
UIViewAutoresizingFlexibleWidth
UIViewAutoresizingFlexibleHeight
For example, let's say you want a view's width to increase when you rotate it to landscape, you want it to maintain the same margins relative to the top, left, and right sides of the screen, and you want its height to remain the same. This means that out of the six attributes above, only the width and bottom margin should be flexible. The other four attributes are fixed. So you would do:
yourView.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
In those rare cases when you can't get the views to behave appropriately using their autoresizingMask property, you can wrap them in a custom view and override that view's layoutSubviews method. This method gets called when the view's frame changes due to autorotation, so you can check [[UIApplication sharedApplication] statusBarOrientation] and update the frames of your subviews manually.
You position them correctly using code the same way you likely positioned them in the original orientation, for example by setting their frame.
As for where in code to do this, check out the various orientation change methods of UIViewController that will be called when the device orientation changes. You could, for example, move/resize the controls in the view within willAnimateRotationToInterfaceOrientation:duration:.

iPhone autoresizing

Is there a "stick-to-bottom" autoresizing mode in Cocoa-Touch? Basically, I got a UIImageView in the lower part of another UIView. When the UIView resizes, I don't want to change the UIImageView's size, but keep it in the lower part of the UIView, while only resizing the other subviews in my UIView above the UIImageView.
Is that easily feasible?
Assuming you want to have the image view resize horizontally:
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;