您还可以像这样使用流畅的动画移动视图
- (void)moveViewPosition:(CGFloat)xPosition forView:(UIView *)view
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[view setFrame:CGRectMake(xPosition, view.frame.origin.y,view.frame.size.width, view.frame.size.height)];
[UIView commitAnimations];
}
并这样称呼它
[self moveViewPosition:120.0f forView:yourView];
更多您还可以修改它以通过这样的函数调用所需的持续时间。
- (void)moveViewPosition:(CGFloat)xPosition forView:(UIView *)view withDuration:(float)duration;
还有其他选择,例如
UIView* view = [self.view viewWithTag:99999];
[UIView animateWithDuration:0.9
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = view.frame;
frame.origin.y = 68;
frame.origin.x = 0;
view.frame = frame;
}
completion:^(BOOL finished)
{
NSLog(@"Completed");
}];