a UIView scaled with animateWithDuration doesn't scale its subviews - objective-c

I have a UIView that contains two UIImageViews.
when I perform animateWithDuration and change its frame (x, y, width, height) , it's subviews aren't resized according to its frame.
How can this be done? is it something with contentMode of the superview or subviews?

You need to configure the subviews auto-resizing rules. If you don't specify any rules the subviews will maintain their size and position (relative to the top left corner).
Check the auto-resizing documentation here. That's the 'simple' version which works from before iOS 6. From iOS 6 onwards you can also use auto-layout which is described here.

Related

How to change UITableViewCell Image to Circle in UITableView if width and height are different

My code is
imv.clipsToBounds=YES;
imv.layer.cornerRadius=imv.frame.size.width/2;
imv.layer.borderWidth = 4.0;
The best solution would be to either resize your image view to be square (using autolayout or manually set the frame) or even better you could redraw the image using an image context with a circular clipping mask, then you wouldn't have performance problems on older devices because of corner radii that you recompute on scrolling.
Something like here https://stackoverflow.com/a/17722702/384309

Scaling a UIView with UIPanGestureRecognizer

I have a rectangle UIView with a UIWebView as a subview, and I want to change the scale when pan is detected on the upper left corner. I already have another small UIView in the upper left corner so the scaling should start from there. I know this can be done by UIPinchGestureRecognizer but having a UIWebView there will be an obstacle for that. I've added a UIPanGestureRecognizer to the main UIView so it's movable. but I want to check if the pan is from the small UIView in the upper left corner and from there change the scale transform of the UIView. So how to do that? Also is it possible to change the scale horizontally/vertically depending on the direction I'm panning the small UIView to? Also is it possible to set a minimum/maximum scale so the UIView won't scale after that?
Thanks
Maybe there is something that you need?
http://rogchap.com/2011/06/10/ios-image-manipulation-with-uigesturerecognizer-scale-move-rotate/

Resizing CAShapeLayer

I have a simple test app on which my rootViewController's UIView contains a bunch of UIView subviews. Each one of those UIView subview is backed by a CAShapeLayer.
I want the composition created by those subviews ( the four shapes that are within the dotted area .. ) to always stay vertically and horizontally centered with respect to my
UIWindow. (the minimium size of the left/right, top/bottom margins will be subject to be changed at runtime at each orientation change )
So for example when i rotate to portrait i will have to
resize and reposition those single shapes so that the whole figure will be mantained centered and each CAShapeLayer sublayer stays sharp ( i want their path to be resized not just a raster resize )
what would be the best technique to resize/move the shapes to always have a centered composition while maintaining path crisp appearance for the shapes?
Ultimately for me it will be good to have an answer to this: how can i shrink the subviews as a whole? i mean their sizes and relative positions?
Thanks
You can use CGPathCreateMutableCopyByTransformingPath() or -[UIBezierPath applyTransform:] to recalculate all points in the path.

Objective C: Adaptive Toolbar On Orientation Change

I am having a problem with my toolbar when i change the orientation of my iPad.
i set my nib file into landscape and everything is all right but when i turned it to portrait my toolbar still has the width from the landscape orientation.
how will i make my toolbar adaptive to the orientation change to portrait?
Landscape:
Portrait:
thanks!
Try adding UIViewAutoresizingFlexibleWidth to the toolbar autoresizingMask like so:
myToolbar.autoresizingMask |= UIViewAutoresizingFlexibleWidth
Or, if your doing this in the Interface Builder, make sure this horizontal bar is selected (others may be selected as well, which is fine):
More from the UIView Class Reference about autoresizingMask:
When a view’s bounds change, that view automatically resizes its
subviews according to each subview’s autoresizing mask. You specify
the value of this mask by combining the constants described in
UIViewAutoresizing using the C bitwise OR operator. Combining these
constants lets you specify which dimensions of the view should grow or
shrink relative to the superview. The default value of this property
is UIViewAutoresizingNone, which indicates that the view should not be
resized at all.
When more than one option along the same axis is set, the default
behavior is to distribute the size difference proportionally among the
flexible portions. The larger the flexible portion, relative to the
other flexible portions, the more it is likely to grow. For example,
suppose this property includes the UIViewAutoresizingFlexibleWidth and
UIViewAutoresizingFlexibleRightMargin constants but does not include
the UIViewAutoresizingFlexibleLeftMargin constant, thus indicating
that the width of the view’s left margin is fixed but that the view’s
width and right margin may change. Thus, the view appears anchored to
the left side of its superview while both the view width and the gap
to the right of the view increase.
If the autoresizing behaviors do not offer the precise layout that you
need for your views, you can use a custom container view and override
its layoutSubviews method to position your subviews more precisely.
In addition to adjusting the flexible width of your toolbar you could create 2 arrays of toolbar items. One for portrait and one for landscape. Fortunately you only have to create the toolbar items once and just add them to the appropriate array(s).
Then during the orientation change you can set the toolbar's items array to the appropriate one.
Good Luck

How do I flip a UILabel horizontally?

I want to develop an iPhone application using the utility template, where the flip side is semi-transparent displaying the contents of the main view, flipped horizontally.
Edit: To create the illusion of semi-transparent flip side, I'd display the same content on the flip view as in the main view, but mirror the content and lower the alpha.
Is it possible to display a text using an UILabel, but mirror the text, ie flip it horizontally? Apple dev pages does not give me any help in this issue.
As August said, I'm not sure of your use case on this, but there's a reasonably straightforward way to do it using Core Animation. First, you'll need to add the QuartzCore framework to your project and do a
#import <QuartzCore/QuartzCore.h>
somewhere in your headers.
Then, you can apply a rotational transform to your UILabel's underlying layer using the following:
yourLabel.layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f);
which will rotate the label's CALayer by 180 degrees (pi radians) about the Y axis, producing the mirror effect you're looking for.
In the Utility template, the flipside isn't shown semi-transparent. This is most likely for performance reasons on the iPhone. I'm not sure there's any value to having your label flipped if it's not providing any functionality.
That said, I'd look into UIView's transform property.