移动视图/用动画改变视图的位置
如果您想根据需要更改 View 的位置,则只需使用以下代码行:
.h 文件:
- (void)moveView:(UIView *)view withDuration:(NSTimeInterval)duration
andCurve:(int)curve inDirection_X:(CGFloat)x inDirection_Y:(CGFloat)y;
.m 文件:
- (void)moveView:(UIView *)view withDuration:(NSTimeInterval)duration
andCurve:(int)curve inDirection_X:(CGFloat)x inDirection_Y:(CGFloat)y
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
view.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
注意:要在任何地方调用上述方法,只要喜欢它,根据您的要求,即如何移动视图/使用动画更改视图的位置
[self moveView:mFrontSideView withDuration:2.0 andCurve:0 inDirection_X: 0.0 inDirection_Y: mBackSideView.center.y + 100.0];