[英]iPhone view move animation
我想點擊一個按鈕時將一個視圖移動到右邊。 我寫了些東西,但它不起作用;
UIView* view = [self.view viewWithTag:100];
if (!view) {
NSLog(@"nil");
}
[UIView animateWithDuration:0.3f
animations:^{
[view setTransform:CGAffineTransformMakeTranslation(-100, 0)];
}
completion:^(BOOL finished){
}
];
試試這段代碼;
UIView* view = [self.view viewWithTag:100];
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = view.frame;
frame.origin.y = 0;
frame.origin.x = (-100);
view.frame = frame;
}
completion:^(BOOL finished)
{
NSLog(@"Completed");
}];
像這樣做 。
leftFrame是您可以開始的框架,右框架是您要移動到的框架
UIView* view = [self.view viewWithTag:100];
if (!view) {
NSLog(@"nil");
}
[vw setFrame:leftFrame];
[UIView animateWithDuration:0.3f
animations:^{
[vw setFrame:rightFrame];
}
completion:^(BOOL finished){
}
];
快樂編碼:)
您還可以使用像這樣的平滑動畫移動視圖
- (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");
}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.