Tag: 核心animation

Swift:影响button点击的UITextfield? 由于animation无法input文字?

我有一个奇怪的问题,我的UIViewanimation和一个UITextfield – 我需要能够点击一个button,让buttonanimation显示一个文本字段,以便用户可以在文本字段中input文本,然后当用户按下再次button,用户交互在文本字段被禁用,并且button移回。 这就是我的意思 – 我已经在一定程度上通过将文本字段放置在button的后面并在开始时将其禁用,然后当单击该button时buttonanimation起来以显示文本字段, 问题是,当用户去编辑文本字段时,button点击正在被触发(或者可能只是animation)。 所以当他们打字的时候,button只是向下移动并覆盖文本框。 这很奇怪,因为我有一个布尔值来设置button是向上还是向下移动的,我不认为这是翻转的,因为通常button在文本区下面移动,这是不应该发生的。 这是我如何做到这一点: @IBAction func enterText(sender: UIButton) { print("time to enter text") if !textOpen { UIView.animateWithDuration(0.5, animations: { self.textBtn.center.y -= self.textBtn.bounds.height }) happenedTxt.userInteractionEnabled = true } else { UIView.animateWithDuration(0.5, animations: { self.textBtn.center.y += self.textBtn.bounds.height }) happenedTxt.userInteractionEnabled = false } textOpen = !textOpen } 当按下button时,如何才能触发button的移动? 为什么文本框会触发animation? 有没有人打电话让button回到原来的位置?

Gradient Layer over ImageView重用

在我的'cellForRowAtIndexPath'我有以下代码来填充图像(asynchronous)并应用自定义渐变 这工作得很好,直到我为每个单元格添加一个自定义颜色。 它现在做的是回收以前的颜色,而不是应用一个新的 – 这大概是由于下面的行将跳过梯度代码一旦应用到每个单元格: if(!cell.gradientMask){ 但是,如果我对此进行注释,则颜色可以正常工作,但每个单元格上的渐变将叠加起来,因为每次都会添加一个新图层(请参阅现有问题 ) 我认为我需要删除每个迭代gradientLayer,是最好的办法或者我可能需要inheritanceUIImageView? if (!cell.gradientMask) { gradientMask = [CAGradientLayer layer]; gradientMask.frame = cell.eventImage.layer.bounds; gradientMask.startPoint = CGPointMake(0.5, 0.2); gradientMask.endPoint = CGPointMake(0.5, 1.0); /* THIS COLOUR CHANGES FOR EACH CELL */ gradientMask.colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:0.0f] CGColor], (id)[[UIColor colorWithRed:0.0f green:0.0f blue:1.0f alpha:1.0f] CGColor],nil]; [cell.eventImage.layer insertSublayer:gradientMask atIndex:0]; cell.gradientMask […]

CATransform3DMakeRotationanimation槽零(从-45到+45angular)?

我正在尝试做一个有反弹效果的简单水平翻转animation。 [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationCurveEaseIn animations:^{ front.layer.transform=CATransform3DMakeRotation(DEGREES_TO_RADIANS(90), -1.0,0.0,0.0); // flip halfway } completion:^(BOOL finished) { // swap view front.alpha=0; back.alpha=1; [UIView animateWithDuration:0.5 animations:^{ // flip remaining + bounce back.layer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(45), 1.0,0.0,0.0); // final + 45 } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ back.layer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(-22.5), 1.0,0.0,0.0); // bounce back } completion:^(BOOL finished) { [UIView […]

animation一个圆圈成长

我用UIImageViewanimation一个圆圈的图像,生长和淡入重复: -(void)animateOuterCircle { NSLog(@"animating circles"); [UIView animateWithDuration:1.5 delay:.5 options:(UIViewAnimationOptionAllowUserInteraction) animations:^{ self.outerCircle.transform=CGAffineTransformMakeScale(.25, .25); } completion:nil]; [UIView animateWithDuration:1.5 delay:.5 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction) animations:^{ self.outerCircle.transform=CGAffineTransformMakeScale(1.5, 1.5); self.outerCircle.alpha = 0; } completion:nil]; [self.view bringSubviewToFront:self.outerCircle]; } 我在viewDidAppear中调用这个方法: – (void)viewDidAppear:(BOOL)animated { [self performSelectorOnMainThread:@selector(animateOuterCircle) withObject:nil waitUntilDone:NO]; //other code } 它将animation罚款时,我加载mainView。 问题是我加载view2和closuresview2,当我回到主视图,它不是animation了。 任何想法为什么发生这种情况? 编辑:方法被称为: 2012-03-15 14:11:13.946[1529:17903] view2 canceled //dismissing view2 2012-03-15 14:11:13.947[1529:17903] mapView […]

我如何使一个图层保持CABasicAnimation的最终值

考虑下面的animation: CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation.duration = 1.0; pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; pathAnimation.removedOnCompletion = NO; pathAnimation.delegate = self; 这将基本上激活图层从一端到另一端的绘制。 问题是一旦animation完成, strokeEnd属性将重置为0(最初设置的位置)。 我如何使最终的价值“坚持”? 我试图在animationDidStop委托方法中改变这个。 这大部分工作,但可以在0简要地引起一个strokeEnd ,甚至当放入一个CATransaction里面禁用animation。 我也玩过additive和cumulative性质无济于事。 有什么build议么?

Swift – 何时或如何在视图上实现animation开始?

我是Swift的新手,我试图实现一个简单的游戏。 在这个游戏中,一旦视图被加载,我想要定期的animation发生。 问题是,我尝试使用例如button.frame.origin.x += 50来设置animation的button,但不是将其从原点移动到50px,而是出现在button.frame.origin.x – 50并转到其(初始)位置。 有趣的是,在某一点上,我向用户显示一个AlertDialog ,并显示后,animation开始发生,如我所料。 我的问题和这个话题是一样的,但是接受的答案并没有为我解决。 有什么想法吗? 编辑:挖到代码和testing了很多我发现了我显示AlertDialog的方法也发生无效我的计时器。 我有两个计时器:一个更新UI时间(一个TextField),另一个执行animation。 两者都正在安排一项任务。 从我在这里读到的 ,不可能有两个这样的计时器。 一个计时器对象一次只能在一个运行循环中注册,尽pipe它可以被添加到该运行循环中的多个运行循环模式中。 因此,显而易见的解决scheme是将两个select器(函数)合并为一个,所以这个计时器将适用于这两个任务。 但是,如果我尝试更新UI并执行animation,则animation不能按预期工作。 我只是迷失在这个问题上,不能使这两件事情的工作。 这些是我的重要代码: override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) … resetOrCreateGame() } func resetOrCreateGame() { // Do stuff to initialize values timerToRotate = NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "rotateBlocks", userInfo: nil, repeats: true) } func rotateBlocks() { // […]

将imageNamed转换为imageWithContentsOfFile:

我的代码为我的图像是 -(IBAction)start:(id)sender { animation.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Paddle 1.png"], [UIImage imageNamed:@"Paddle 2.png"], [UIImage imageNamed:@"Paddle 3.png"], [UIImage imageNamed:@"Paddle 4.png"], nil]; [animation setAnimationRepeatCount:0]; animation.animationDuration = 2.5; [animation startAnimating]; } 这是caching太多的内存,我在前面的问题被告知交换我的代码使用 [UIImage imageWithContentsOfFile: GetImgWithoutCaching(@"Paddle 1.jpg")] 和 UIImage* GetImgWithoutCaching(NSString* imgName) { NSString *imagePath = [[NSBundle mainBundle] pathForResource:imgName ofType:nil]; return [UIImage imageWithContentsOfFile:imagePath]; } 编写代码的正确方法是什么? 我是否将该代码放在我的.m中?

第一个键盘外观animation有时不顺畅

我经常注意到,当第一次出现键盘时,第一个成为第一个响应事件的时候,UIViewanimation通常是不stream畅的。 我指的是与键盘animation发生的animation,例如手动滚动UIView以使textField可见。 animation在第一次执行后总是平滑的。 有这样的技术原因吗? 我在想,在第一次运行时可能会有一些惰性加载或优化发生在UIViewanimation中,然后存储在caching中以供重用。 有没有经验教训? 如果对这个观众不清楚,我可以尝试在testing项目中重新创build问题。

iOS Webkitanimation性能仅在视网膜显示上受损

我有一个使用CSS转换的移动应用程序来设置各种页面元素的不透明度(淡入淡出)。 另外值得注意的是,我在整个页面中都使用了embedded式字体。 我注意到,在iPhone 4上,该页面的性能是绝对可怕的,只有在该设备上。 在3GS的performance就好了。 animation不仅动荡不安; 即使滚动页面,并点击页面元素,如select标签需要永远。 任何人都可以看到提高视网膜显示iPhone上的animation/渲染性能?

如何在UIView中使用setAnimationStartDate?

如何使用setAnimationStartDate?下面的代码不起作用。 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:3.0]; NSDate *date = [NSDate dateWithTimeIntervalSinceNow:3]; [UIView setAnimationStartDate:date]; CGPoint point = _imageView.center; point.y += 150; [_imageView setCenter:point]; [UIView commitAnimations];