【问题标题】:Create custom animation like transitionWithView block创建自定义动画,如 transitionWithView 块
【发布时间】:2015-11-19 11:03:52
【问题描述】:

我正在使用transitionWithView 动画块为视图设置动画。当用户向左或向右滑动视图时调用此块。它工作正常。但是我想创建自己的自定义动画,例如视图从左到右方向发生变化。我不知道如何实现这一点。我正在使用UIViewAnimationOptionTransitionCurlUp 从右向左滑动 和UIViewAnimationOptionTransitionCurlDown 用于从左向右滑动UIViewAnimationOptions

[UIView transitionWithView:self.view duration:0.6 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        setDataInLayout();
    } completion:^(BOOL finished) {
        [scrollViewContent setContentOffset:CGPointZero animated:YES];
        [self.delegate updatePaginationCounter:_currentStoneIndex];
    }];

【问题讨论】:

    标签: ios objective-c iphone ipad


    【解决方案1】:

    你必须自己实现这个动画。我会使用 UIView 动画 API,例如:

    UIView.animateWithDuration(0.6, animations: {
        // apply 2D transformation to the view, or use any other animatable property
        self.view.transform = CGAffineTransformMakeRotation(fullRotation)
    } completion: {finished in
            // you completion block    
    })
    

    这里是 UIView 的动画属性的list。对于更复杂的动画,您可以使用基于关键帧的动画:

    UIView.animateKeyframesWithDuration(duration, delay: delay, options: options, animations: {
    // add your keyframe animations here
    
    UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/2, animations: {
        self.view.transform = ...
    })
    UIView.addKeyframeWithRelativeStartTime(1/3, relativeDuration: 1/2, animations: {
        self.view.transform = ...
    })
    
    }, completion: {finished in
        // completion block
    })
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      相关资源
      最近更新 更多