Why are animations on bounds of an UILabel only working when increasing the size?
It's because UILabel
sets its layer's contentsGravity
to the direction text is being rendered, which happens to default to UIViewContentModeLeft
(or @"left"
). Thus, when the layer is told to animate, it first takes a glance at its contents gravity and bases subsequent animations on that. Because it sees @"left"
where there should be @"resize"
, it assumes that the scaling animation should begin from the left, but it also has to respect the constraints you've given it (the bounds changes), so your label appears to jump into its final size then settle where it should in the center of the screen.
If you want to leave contentMode
alone, use CATransform3D
's and scale the label's layer that way instead of a bounds change.
Animating UILabel size decrease
I think what you are wanting to change is the bounds, rather than the frame. From the docs:
"The bounds rectangle determines the origin and scale in the view’s coordinate system within its frame rectangle and is measured in points. Setting this property changes the value of the frame property accordingly." - UIView Class; bounds property
Try something like:
- (void)animate:(id)sender
{
...
CGRect newBounds = testLabel.bounds;
newBounds.size.height += 50;
testLabel.bounds = newBounds;
...
}
iOS - Animating text size change in UILabel or UITextView?
If I knew when the rotation was about
to start, and the duration of the
animation...
Funny you should mention that. Just before the animation starts, your view controller will receive a willAnimateRotationToInterfaceOrientation:duration:
message that gives you the exact information you need.
Animating UILabel Font Size Change
You can change the size and font of your UILabel
with animation like bellow .. here I just put the example of how to change the font of UILabel
with transform Animation ..
yourLabel.font = [UIFont boldSystemFontOfSize:35]; // set font size which you want instead of 35
yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 0.35, 0.35);
[UIView animateWithDuration:1.0 animations:^{
yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 5, 5);
}];
Animating Frame of UILabel smoothly
Hooray for answering a two-year dead question, but I found the answer. Either in Interface Builder or in code, change the contentMode
property of the label. Yours seems to be set on scaleToFill
; try left
or right
.
Animate UILabel text size increase and decrease
The font of a UIView is not an animatable property. You should use transforms instead.
[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.transform = CGAffineTransformMakeScale(2.0, 2.0); //increase the size by 2
//etc etc same procedure for the other labels.
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];
similarly, you can play with the values in CGAffineTransformMakeScale(x, y);
- x is the horizontal scale constant and y is the vertical one. Enjoy!!
Expanding Multiline UILabel
I had a similar problem trying to make a view grow/shrink. Here is my SO post.
Basically I had to animate the frame to grow and then bounds/center to shrink. A bit awkward I know but I got the effect I wanted.
UILabel animate the width
I was able to do it in this way. self refers to the view in which i'm adding the label. in the init, add the label with width as 1 px. then use the below.. the UIViewAnimationOptionBeginFromCurrentState allows it to be opened like a door PHEW!
[UIView animateWithDuration:1. delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self setFrame:CGRectMake(self.frame.origin.x-labelSize.width-PADDING, self.frame.origin.y, self.frame.size.width+labelSize.width+PADDING, self.frame.size.height)];
[self.messageLabel setFrame:CGRectMake(95, 10, labelSize.width, labelSize.height)];
self.messageLabel.alpha = 1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:2. options:0 animations:^{
self.messageLabel.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:0. options:0 animations:^{
[self setFrame:CGRectMake(self.frame.origin.x+labelSize.width+PADDING, self.frame.origin.y, self.frame.size.width-labelSize.width-PADDING, self.frame.size.height)];
} completion:^(BOOL finished) {
}];
}];
}];
Related Topics
Symbolicate Crash in iOS8 with Xcode 6 .1
Where Is the Official Documentation for Cvopenglestexture Method Types
Removing Object from Array in Swift 3
Info.Plist Utility Error: "Info.Plist Couldn't Be Opened Because There Is No Such File"
How to Debug an Issue with a Release Mode Build in iOS
How to Get the MAC Os X Firewall to Permanently Allow My iOS App
How Do Set a Width and Height of an Image in Swift
How to Implement Localization in Swift Ui
Less Blur with 'Visual Effect View with Blur'
What Is Container View in iOS 5 Sdk
iOS Enterprise Provisioning Profile Expiration
Add Uiview Banner Above Status Bar iOS 7
Pulling Data from a Cmsamplebuffer in Order to Create a Deep Copy
Delete Cell from Uicollectionview Without Reloading from Top
How to Resize Uitableviewcell to Fit Its Content
Uinavigationcontroller Interactivepopgesturerecognizer Working Abnormal in iOS7