iPhone autoresizing - iphone

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;

Related

UIImageView "squashed" after CGAffineTransformMakeRotation

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

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.

Iphone--(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

I By using this command
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
I can rotate my view automatically ,Is there any way to rotate and ellabarate and fit with screen.
Thanks in advance,
(Deepan)
You can use the autoresizing properties of your views to make them resize to fit the screen.
For example, if you want a view to resize horizontally and vertically, you can use:
myView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
To control whether a view will automatically resize its subviews, you use the boolean autoresizesSubviews property.
To control how a container view will layout its subviews when the container view's size changes, you use the contentMode property.
For more information, refer to Apple's UIView Class Reference.

Auto resize subviews on device rotation

I have all my subviews set up so that they are based on self.view.
EG: UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,(self.view.frame.size.width-20),(self.view.frame.size.height-90))];
however when the view rotates (shouldRotateToDeviceOrientation or whatever) the views all stay the same size. How can I make them change shape to fit? Can I do this automatically?
Thanks
Absolutely. Take a look at the autoresizingMask property. If you set your image view, in this case, to have an autoresizing mask of UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight, then when its parent view resizes (as it may or may not automatically do when your app rotates—you might have to set a similar autoresizingMask on the parent view), it'll maintain the exterior margins you set up for it.
Just in case you have a view in the bottom of parent view this should help:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
Where self is your child view, that should be resized. If you do not set UIViewAutoresizingFlexibleTopMargin, then in horizontal mode you will not see your view, if it was in the bottom in vertical mode.
Also do not forget to set:
self.autoresizesSubviews = YES;
And autoresizing modes for all child view in your view. So that when it is resized, everything inside it also gets resized.
you have to [view setAutoresizingMask:...]

How to resize UIlabel inside UIView proportionally?

I have a UILabel inside a UIView and I want the label to be resized proportionally as the UIView is resize.
I was able to do so with a UIImageView but the label stays as big as I placed it in IB.
I have set the view contentMode to UIViewContentModeScaleAspectFit thinking that anything inside the UIView would be "aspect fit" but I had to set the same mode to the UIImageView (which works fine) and I can't set that mode to the UILabel.
Thanks for your help.
It appears CGAffineTransform is the answer.
myView.transform = CGAffineTransformMakeScale(0.5, 0.5);
This would resize the view and everything that is inside dividing the view width and height by 2.
set setAutoresizingMask of label