2 sachinks SachinKS 于 2013.02.17 14:18 提问

iphone--视图移动动画

我需要点击按钮时往右移动视图,写的代码没有实现:

UIView* view = [self.view viewWithTag:100];
if (!view) {
    NSLog(@"nil");
}

[UIView animateWithDuration:0.3f 
                 animations:^{
                     [view setTransform:CGAffineTransformMakeTranslation(-100, 0)];

                 }
                 completion:^(BOOL finished){

                 }
 ];

2个回答

loFataMer
loFataMer   2013.02.17 15:21
已采纳

用这段代码试试:

  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");

         }];
redCoral_
redCoral_   2013.02.17 14:43

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){
                 }
 ];
Csdn user default icon
上传中...
上传图片
插入图片