简体   繁体   English

创建自定义动画,例如transitionWithView块

[英]Create custom animation like transitionWithView block

I am using transitionWithView animation block to animate view. 我正在使用transitionWithView动画块对视图进行动画处理。 This block is called when user swipe the view in left or right direction. 当用户向左或向右滑动视图时,将调用此块。 It works fine. 工作正常。 But I want to create my own custom animation like view gets changed from left to right direction. 但是我想创建自己的自定义动画,例如视图从左向右更改。 I don't know how to achieve this. 我不知道该如何实现。 I am using UIViewAnimationOptionTransitionCurlUp for right to left swipe and UIViewAnimationOptionTransitionCurlDown for left to right swipe in UIViewAnimationOptions . 我使用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];
    }];

You have to implement this animation by yourself. 您必须自己实现此动画。 I would use UIView animation API like: 我将使用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    
})

Here is the list of UIView's animatable properties. 这是UIView的动画属性列表 For more complex animations you can use the keyframe-based animation: 对于更复杂的动画,可以使用基于关键帧的动画:

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
})
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS/Objective-C:transitionWithView 自定义 animation 块立即调整视图大小,而不是超过持续时间 - iOS/Objective-C: transitionWithView custom animation block resizes view immediately, not over duration 使用动画块外部的更改时,UIView transitionWithView平滑 - UIView transitionWithView is smooth when using changes outside of animation block transitionWithView不执行翻转动画 - transitionWithView Not Performing Flip Animation 有没有办法在 transitionWithView 中使用 presentViewController 动画? - Is there a way to use presentViewController animation in transitionWithView? UIView transitionWithView:具有背景颜色的动画行为 - UIView transitionWithView: animation behaviour with background color Swift:UIView.transitionWithView完成块问题 - Swift: UIView.transitionWithView completion block issues 如何创建自定义相机快门动画(例如在SocialCam应用中) - How to create a custom camera shutter animation (like in SocialCam app) 在Xamarin中使用transitionWithView设置UIView.Hidden属性时淡出动画 - Fade animation when setting UIView.Hidden property with transitionWithView in Xamarin UIView transitionWIthView 简单的改变图像动画——如何明确提及“自我” - UIView transitionWIthView simple change image animation — how to explicitly mention ‘self’ 如何创建这样的动画? - How to create an animation like this one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM