CABasicAnimation中的问题,将帧从ios中的位置更改为另一个位置
有很多关于如何设置UIView动画的教程: 这里还有一个可能有用的例子CABasicAnimation中的问题,将帧从ios中的位置更改为另一个位置,ios,cabasicanimation,Ios,Cabasicanimation,有很多关于如何设置UIView动画的教程: 这里还有一个可能有用的例子 the label is not animating . . . . UILabel * m_pLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 100, 40)]; [m_pLabel setBackgroundColor:[UIColor redColor]]; [self.view addSubview:m_pLabel];
the label is not animating . . . .
UILabel * m_pLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 100, 40)];
[m_pLabel setBackgroundColor:[UIColor redColor]];
[self.view addSubview:m_pLabel];
CABasicAnimation * m_pAnimationObj = [CABasicAnimation animationWithKeyPath:@"key"];
[m_pAnimationObj setFromValue:[NSValue valueWithCGRect:CGRectMake(100, 10, 100, 40)]];
[m_pAnimationObj setToValue:[NSValue valueWithCGRect:CGRectMake(100, 500, 100, 40)]];
m_pAnimationObj.duration = 5.0;
m_pAnimationObj.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[m_pLabel.layer addAnimation:m_pAnimationObj forKey:@"key"];
有很多关于如何设置UIView动画的教程: 这里还有一个可能有用的例子
the label is not animating . . . .
UILabel * m_pLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 100, 40)];
[m_pLabel setBackgroundColor:[UIColor redColor]];
[self.view addSubview:m_pLabel];
CABasicAnimation * m_pAnimationObj = [CABasicAnimation animationWithKeyPath:@"key"];
[m_pAnimationObj setFromValue:[NSValue valueWithCGRect:CGRectMake(100, 10, 100, 40)]];
[m_pAnimationObj setToValue:[NSValue valueWithCGRect:CGRectMake(100, 500, 100, 40)]];
m_pAnimationObj.duration = 5.0;
m_pAnimationObj.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[m_pLabel.layer addAnimation:m_pAnimationObj forKey:@"key"];
当前,您要求动画处理@“关键点”属性,而它在逻辑上应该是@“帧”属性。但是,无论如何,这在图层上都不起作用。动画必须知道将指定的更改应用于什么,但它还需要能够将更改应用于“true”属性。“框架”是一个派生属性 要更改位置,需要为“位置”设置动画,并更改为“边界”属性设置动画所需的大小
请参阅此苹果技术说明:当前,您要求动画处理@“key”属性,而它在逻辑上应该是@“frame”属性。但是,无论如何,这在图层上都不起作用。动画必须知道将指定的更改应用于什么,但它还需要能够将更改应用于“true”属性。“框架”是一个派生属性 要更改位置,需要为“位置”设置动画,并更改为“边界”属性设置动画所需的大小
请参阅此苹果技术说明:试试这个……希望这对您有所帮助
//UIViewAnimationOptionAutoreverse option, try the code below:
UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 300.0f, 200.0f)];
[testView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:testView];
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[testView setFrame:CGRectMake(0.0f, 100.0f, 300.0f, 200.0f)];
}
completion:nil];
[testView release];
试试这个……希望这对你有帮助
//UIViewAnimationOptionAutoreverse option, try the code below:
UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 300.0f, 200.0f)];
[testView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:testView];
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[testView setFrame:CGRectMake(0.0f, 100.0f, 300.0f, 200.0f)];
}
completion:nil];
[testView release];
谢谢,我只想通过CABasicAnimation对象制作此动画。你能帮我吗?我只想通过CABasicAnimation对象制作这个动画。你能帮我把钥匙换成相框,但运气不好。。。。标签未设置动画。。。我必须在外部设置动画吗?你更改了关键点和关键点路径?我已将关键点更改为帧,但运气不好。。。。标签未设置动画。。。我必须在外部设置动画吗?你更改了关键点和关键点路径?