我试图将UILabel
帧设置为屏幕中间位置的动画。相反,它似乎是从视图之外的某个地方动画回到其原始位置。
[UIView beginAnimations:@"labelAnim" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1.0];
[self.scoreLabel setFrame:self.endScoreFrame];
[UIView commitAnimations];
以下是起始帧和结束帧:
Start Frame: {{10, 30}, {144, 21}}
Final Frame: {{93.75, 158.71438598632812}, {187.5, 46.875}}
答案 0 :(得分:0)
试试此代码
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self.scoreLabel setFrame:self.endScoreFrame];
} completion:^(BOOL finished) {
NSlog("completed");
}];
并确保您的endScoreFrame
具有正确的新位置坐标:
NSLog(@"%@", NSStringFromCGRect(self.endScoreFrame));
我已经使用旧框架和新框架的值测试了此代码,并且工作正常:
@property (nonatomic, strong) UILabel *lbl;
viewDidLoad中:
self.lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 144, 21)];
self.lbl.text = @"mylabel";
[self.view addSubview:self.lbl] ;
行动
-(void)btnClick:(id)sender
{
CGRect newFrame = CGRectMake(93.75, 158.71438598632812, 187.5, 46.875);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.lbl.frame = newFrame ;
} completion:^(BOOL finished) {
}];
}
答案 1 :(得分:0)
我发现了问题。我忘记了我在Interface Builder中设置了标签,因此它被覆盖了。