Tag: core animation

翻转和缩放3D转换问题(iOS 7+)

我正在尝试构build卡片翻转和缩放的转换。 我已经在折纸 – 电影(less于1Mb) 正如你所看到的,同时应用了3个变换:1.将视图的中心移动到屏幕的中心2.缩放3. 3D旋转 我们可以分为两个阶段的animation: 阶段1:button缩放,移动并在侧面旋转(PI / 2弧度)。 在阶段1结束时button消失。 阶段2: toView (我的模态视图)旋转(从-PI / 2到0弧度),放大到正常大小,并将视图的中心移动到屏幕中心。 如果我们排除反弹 – 这是非常简单的转换。 但是在构build时遇到了一些问题: 我只是一个button,而不是整个视图。 这个button背后有一个背景。 所以,如果我应用CATransform3DMakeRotationbutton的一半消失 – 它与3D空间(Z轴)中的背景相交。 有没有办法在这里使用3DTransform? 2.屏幕上有一些文物。 我不知道他们来自哪里。 你可以检查结果电影 (3.8Mb)。 我放慢了电影中第二张卡片的animation。 这是我的这个animation的代码: func animateTransition(transitionContext: UIViewControllerContextTransitioning) { let container = transitionContext.containerView() let fromViewBig = transitionContext.viewForKey(UITransitionContextFromViewKey)! let toView = transitionContext.viewForKey(UITransitionContextToViewKey)! // Converting button to UIImageView and hiding […]

UIViewanimation在视图顶部与轴交替

我有一个UIView ,我想animation翻转起来。 这不像UIViewAnimationOptionTransitionFlipFromTop因为那将轴放置在视图的中间。 我想将轴放在视图的top ,以便翻转起来,类似于一张纸从top axis翻转(不是页面剥离)。 [UIView transitionWithView:self.view duration:0.6 options:UIViewAnimationOptionTransitionFlipFromTopAxis // <—- Wish there was an option like this animations:^{ // Exchange the views here } completion:NULL]; 我想这是不可能做到这一点与标准的UIViewanimation选项。 有什么替代方法,我可以控制翻转轴?

将UILabel的位置改为CGPath的strokeEnd

我正在尝试实现与附加图像类似的function,根据您的关卡进度将圆圈设置为animation,然后将标签附加到animationpath的末尾以显示获得的体验以及圆圈的未绘制部分以显示其余的经验。 我有圈子animation想要通过,但有麻烦提出解决scheme的标签出现在正确的位置。 我已经尝试将标签的位置设置为path.currentPoint,但总是似乎是绘制path的开始,而不是结束。 任何关于如何实现这一点的指针都会很棒!

在CABasicAnimation中闪烁以进行旋转

我正在试图从一个angular度旋转一个CAShapeLayer,只要按下一个button,它就会从当前angular度开始旋转。 我正在使用委托函数animationDidStop在animation结束时设置图层的变换,因为我已经注意到animation只改变了表示层的变换而不是本身的图层。 但是在animation结束时,animation完成时,由于图层在委托函数animationDidStop中更新转换之前返回到其上一个变换,animation中会出现随机闪烁。 我如何消除闪烁? @implementation ViewController – (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { [CATransaction begin]; [CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions]; self.parentLayer.transform = CATransform3DRotate(self.parentLayer.transform, DEG2RAD(60.0), 0, 0, 1); [CATransaction commit]; } – (IBAction)rotateBySixtyPressed:(id)sender { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.duration = 3.0; animation.byValue = [NSNumber numberWithFloat:DEG2RAD(60.0)]; [animation setDelegate:self]; [self.parentLayer addAnimation:animation forKey:animation.keyPath]; }

禁用CALayer隐式animation

下面的类正试图阻止CALayer更改属性时发生的任何隐式animation。 // NoImplicitAnimations.h #import <Foundation/Foundation.h> #import <QuartzCore/QuartzCore.h> @interface NoImplicitAnimations : NSObject – (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key; @end // NoImplicitAnimations.m #import "NoImplicitAnimations.h" @implementation NoImplicitAnimations – (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key { return (id)[NSNull null]; } @end 我将Objective-C中的NoImplicitAnimations.h导入Swift桥接头。 我创build一个全局常量let _noImplicitAnimations = NoImplicitAnimations() 。 我这样扩展CALayer类: extension CALayer { func noImplicitAnimations () { delegate = _noImplicitAnimations } } […]

animation时更新视图的框架

我正在做这样的animation: CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.duration = 100.0; animation.path = self.animationPath.CGPath; [view.layer addAnimation:animation forKey:@"animation"]; 工作正常,但是,现在尝试检测在屏幕上移动的对象的触摸时失败: – (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView* subview in self.subviews ) { if ( [subview hitTest:[self convertPoint:point toView:subview] withEvent:event] != nil ) { [self handleTap]; return YES; } } return NO; } 它失败了,因为视图的框架不再是它在animation时在屏幕上的明显位置。 我怎样才能让pointInside与正在animation的视图一起工作?

在UIImage上添加Tap手势

我正在尝试使可点击的UIImage,用户可以点击它,然后它会animation… 我正在使用UIScrollVIew,这就是为什么我使用UITapGesture而不是touchesBegan,而且似乎UIGestureRecognizer与UIImage不兼容… 我对吗? 我不断收到这个错误信息 对于实例消息,接收方types“UIImage”不声明带有select器“addGestureRecognizer”的方法 有没有其他方法?

核心animation隐式animation不会为新添加的子层触发

不知道为什么这不起作用。 我不能为新添加的子层做隐式animation,除非有人甚至像触发button或从另一个方法中调用它。 即使我认为我应该这样下面这个不animation。 它只是显示图层的“之后”状态。 CAGradientLayer *newBar = [CAGradientLayer layer]; CGFloat barHeight = ((pair.amount.floatValue/self.model.maxModelValue.floatValue)*maxBarHeight); newBar.bounds=R(0,0,self.barWidth,0); newBar.anchorPoint=P(0, 1); newBar.position=P((i*barSpacing), self.insideLayer.bounds.size.height); newBar.backgroundColor=self.lowerColor.CGColor; newBar.colors=[NSArray arrayWithObjects:(id)self.upperColor.CGColor, self.lowerColor.CGColor, nil]; newBar.cornerRadius=self.cornerRadius; newBar.opacity=1.0; [self.insideLayer addSublayer:newBar]; //animation line: newBar.opacity=0.5;

如何使图像旋转(animation)

我有一个广场的形象,我知道如何让它旋转。 animation旋转…然后停下来…然后再旋转…等等。 我只是一个基本的旋转,但不像上面的GIF: extension UIView { func rotate360Degrees(duration: CFTimeInterval = 3) { let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation") rotateAnimation.fromValue = 0.0 rotateAnimation.toValue = CGFloat(M_PI * 2) rotateAnimation.isRemovedOnCompletion = false rotateAnimation.duration = duration rotateAnimation.repeatCount=Float.infinity self.layer.add(rotateAnimation, forKey: nil) } } 任何想法如何做到这一点?

翻转视图animation不工作

我正在研究一个iPad应用程序,在视图中向用户提出问题。 当他们回答这个问题时,我希望这个观点转向另一个包含下一个问题的观点。 为了使它看起来很花哨,我正在试图添加一个curl转换,但我写的代码不起作用,我可以看不到find问题。 它确实显示正确的视图,但没有过渡animation。 那是什么? 以下是我用来转换的方法: – (void)pageChangedTo:(NSInteger)page { if ( (page == currentQuestionNumber) || (page > ( [self.allQuestions count] – 1 ) ) || (page < 0) ) { return; } AskQuestionView *view = [self.questionViews objectAtIndex:page]; UIViewAnimationTransition transition; if (page > currentQuestionNumber) { transition = UIViewAnimationTransitionCurlUp; } else { transition = UIViewAnimationTransitionCurlDown; } if […]