Objective c 保持动画的结束位置
我什么都试过了,但每次都是一样的问题: 我想移动y=276的按钮。当动画结束时,我的按钮跳回startposition,但我希望endanimationposition是新位置,并且按钮必须保持在那里,直到调用新动画为止 试用Objective c 保持动画的结束位置,objective-c,animation,Objective C,Animation,我什么都试过了,但每次都是一样的问题: 我想移动y=276的按钮。当动画结束时,我的按钮跳回startposition,但我希望endanimationposition是新位置,并且按钮必须保持在那里,直到调用新动画为止 试用 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; CGPoint p = _cell00.center; p.x += 10
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
CGPoint p = _cell00.center;
p.x += 100;
_cell00.center = p;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
同样的问题
[UIView animateWithDuration:1.0 animations:^{
_cell00.frame = CGRectOffset(_cell00.frame, 0, 20);
}];
或
编辑:
我把这个动画和我的按钮叫做statisticsBUttonPressed
- (IBAction)statisticsButtonPressed:(id)sender {
if (statOrGame == 0) {
statOrGame = 1;
}else {
statOrGame = 0;
}
NSLog(@"statOrGame? %d", statOrGame);
[self animateView:(UIButton *)sender];
}
-(void) animateView:(UIButton *)sender {
sender.userInteractionEnabled = NO;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch
NSLog(@"IS IPHONE 5");
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 568)
{
if (statOrGame) {
[UIView animateWithDuration:1.0 animations:^{
_cell00.frame = CGRectOffset(_cell00.frame, 0, 20);
}];
}
}
}
}
问题是您正在使用自动布局。不能(仅)更改通过“自动布局”定位的视图的框架,因为视图的位置取决于其约束。您需要更改约束。您可以在动画结束时执行此操作,也可以简单地设置约束更改的动画。您将此代码称为何处?你能发更大的帖子吗?我编辑了我的问题:)你是最好的!我不需要自动布局,因为我每个设备都有自己的故事板,我只是取消选中自动布局,它就可以工作了!非常感谢!
- (IBAction)statisticsButtonPressed:(id)sender {
if (statOrGame == 0) {
statOrGame = 1;
}else {
statOrGame = 0;
}
NSLog(@"statOrGame? %d", statOrGame);
[self animateView:(UIButton *)sender];
}
-(void) animateView:(UIButton *)sender {
sender.userInteractionEnabled = NO;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{ // The iOS device = iPhone or iPod Touch
NSLog(@"IS IPHONE 5");
CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
if (iOSDeviceScreenSize.height == 568)
{
if (statOrGame) {
[UIView animateWithDuration:1.0 animations:^{
_cell00.frame = CGRectOffset(_cell00.frame, 0, 20);
}];
}
}
}
}