如何在标签上添加animation?
我在ios 7中工作。我是xcode的初学者。 我正在使用故事板。 通过从第一个视图中点击任何一行表格,它将进入第二个视图,并打印被点击的行数和部分数量。 我想要打印行号的标签来自左侧或右侧的animation。 任何人都可以帮助我吗?
你可以很容易地使用UIViewanimation来达到这个目的。 用法取决于您如何将您的标签放在屏幕上。
1-如果您已经使用storyboard将其放置在视图上,并且使用了自动布局,那么您需要将约束链接到视图控制器头文件中的出口,以便为常量值设置animation。
[UIView animateWithDuration:0.2f animations:^{self.labelConstrint.constant=anyNumberoulike; [self.view layoutIfNeeded]; }];
2-如果你使用的故事板没有自动布局(你应该),或者如果你正在代码中创build你的标签,animation只是animation标签的框架矩形的x或y部分。
[UIView animateWithDuration:0.2f animations:^{ self.label.frame=CGRectMake(finaLocationsX,self.label.frame.origin.y,self.label.frame.size.width, self.label.frame.size.height); }];
如果你想在UILabel上做一些animation时,你需要像下面那样创build一个CATransition。
CATransition *transition = [CATransition animation]; transition.type = kCATransitionFade;
之后,添加一层animation到您的标签。如下所示
[self.lblUnit.layer addAnimation:transition forKey:@"changeTextTransition"];
ViewDidLoad–
YOURLABEl=[[UILabel alloc]init]; YOURLABEl.frame=CGRectMake(x, y, width, height); [self.view addSubview:YOURLABEl]; [self.view bringSubviewToFront:YOURLABEl]; [self StartButtonAnimate];
– >然后制作一个方法使其成为animation
-(void)StartButtonAnimate [UIView beginAnimations:Nil context:Nil]; [UIView setAnimationDuration:2]; YOURLABEl.transform=CGAffineTransformMakeTranslation(for X coordinate,for Y coordinate); [UIView commitAnimations];
记住 transaltion它将使用你的UILabel的帧大小,所以相应地传递X和Y.
- 我如何同时animationUIImageView的图像和UIImageView本身?
- animationCALayer背景颜色和更新模型值
- 用autoreverse UIViewanimation
- UITapGestureRecognizer不起作用时,我UIImageViewanimation
- 如何在UIView中使用setAnimationStartDate?
- 获取由UIView的animateWithDuration创build的animation的参考或通过任何其他方式识别它
- 核心animation图像序列
- UICollectionView布局更改的默认animation持续时间是多less?
- 如何Facebook风格的过渡