Tag: uiviewanimation

如何停止和扭转UIViewanimation?

我有一个UIView的animation,以便它在用户触摸一个切换button时收缩,当用户再次触摸button时,它将扩展回原始大小。 到目前为止,一切正常。 问题是animation需要一些时间 – 例如3秒。 在此期间,我仍然希望用户能够与界面进行交互。 所以当用户在animation仍在进行的时候再次触摸button时,animation应该停止在原来的位置并且反向。 在苹果问答中,我发现了一种立即暂停所有animation的方法: https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html 但我没有看到从这里倒转animation的方法(并省略了最初的animation的其余部分)。 我如何做到这一点? – (IBAction)toggleMeter:(id)sender { if (self.myView.hidden) { self.myView.hidden = NO; [UIView animateWithDuration:3 animations:^{ self.myView.transform = expandMatrix; } completion:nil]; } else { [UIView animateWithDuration:3 animations:^{ self.myView.transform = shrinkMatrix; } completion:^(BOOL finished) { self.myView.hidden = YES; }]; } }

用autoreverse UIViewanimation

我有设置UIViewAnimationOptionAutoReverse问题。 这是我的代码。 CALayer *aniLayer = act.viewToChange.layer; [UIView animateWithDuration:2.0 delay:1.0 options:(UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse) animations:^{ viewToAnimate.frame = GCRectMake(1,1,100,100); [aniLayer setValue:[NSNumber numberWithFloat:degreesToRadians(34)] forKeyPath:@"transform.rotation"]; } completion:nil ]; 问题在于,在animation颠倒之后,视图跳回到animation块中设置的帧。 我希望这个观点能够成长并“放弃”,并停止在原来的位置上。 有没有编程两个连续的animation解决scheme?

popViewController的完成块

当使用dismissViewController解除模态视图控制器时,可以select提供一个完成块。 有没有类似的popViewController ? 完成论证是非常方便的。 例如,我可以使用它阻止从tableview中删除一行,直到模式被closures,让用户看到行animation。 从推视图控制器返回时,我想同样的机会。 我已经尝试将popViewController放置在一个UIViewanimation块中,我可以访问完成块。 但是,这会对正在popup的视图产生一些不需要的副作用。 如果没有这样的方法,有什么解决方法?

有没有办法改变一个UILabel的textAlignmentanimation?

我正在使用iOS 7,我试图移动一个标签,它位于我的视图的左侧。 目前我正在尝试通过改变我的UILabel如何alignment来实现这一点,我正在尝试在这个过程中对它进行animation处理。 我目前正在呼叫以下内容: [UIView animateWithDuration:0.5 animations:^{ self.monthLabel.textAlignment = NSTextAlignmentLeft; } completion:nil]; 但是这只是将标签跳到新的路线。 有没有一种方法来animation,或更好的方式来调整标签,使之发生?

在UICollectionView中创build慢速滚动到indexPath

我正在一个项目中使用UICollectionView来创build一个“图片报价器”,我在这里宣传一系列的标志。 collectionView是一个项目高,十二个项目,并一次显示两到三个项目(取决于标志的大小可见)。 我想从第一个项目到最后一个缓慢的自动滚动animation,然后重复。 有没有人能够做到这一点? 我可以使用滚动工作 [myCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:(myImages.count -1) inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:YES]; 但是这太快了! [UIView animateWithDuration:10 delay:2 options:(UIViewAnimationOptionAutoreverse + UIViewAnimationOptionRepeat) animations:^{ [myCollection scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:(myImages.count -1) inSection:0] atScrollPosition:UICollectionViewScrollPositionRight animated:NO]; } completion:nil]; 这会产生所需的滚动速度,但只有最后几个单元格在系列中可见。 我怀疑他们(甚至是初始的可见单元格)正在立即出院。 有什么想法吗?

为什么UILabel的边界上的animation只有在增大尺寸时才起作用?

我注意到,当我改变一个animation块中的UILabel的边界,它只能工作,如果我增加的大小,当我减less大小的UILabel只是改变他的大小,但不animation。 用一个普通的UIViewreplaceUILabel按预期工作。 注意:将UILabel的contentMode属性更改为UIViewContentModeScaleToFill可修复此问题,但我仍然不明白为什么它在不更改contentMode属性的情况下增加大小时会起作用。 #import "FooView.h" @interface FooView () @property (strong, nonatomic) UILabel *label; @property (assign, nonatomic) BOOL resized; @end @implementation FooView – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor lightGrayColor]; self.label = [[UILabel alloc] initWithFrame:(CGRect){0, 0, frame.size}]; self.label.backgroundColor = [UIColor greenColor]; [self addSubview:self.label]; _resized = false; UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer […]

自定义Segueanimation

我正在尝试使用自定义的segue来执行一种缩放animation。 当转换执行时,sourceViewController变黑,然后变焦。 也尝试将pushViewController:设置到完成块中,但是根本不执行转换。 – (void)perform { UIViewController *sourceViewController = (UIViewController *) self.sourceViewController; UIViewController *destinationViewController = (UIViewController *) self.destinationViewController; [destinationViewController.view setTransform:CGAffineTransformMakeScale(0.5,0.5)]; [destinationViewController.view setAlpha:0.0]; [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{ [destinationViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)]; [destinationViewController.view setAlpha:1.0]; [sourceViewController.navigationController pushViewController:destinationViewController animated:NO]; } completion:^(BOOL finished){ }]; } 我做错了什么?

如何使UIViewanimation序列重复和自动反向

如何使这个复杂的animation重复和自动反向? 有没有什么办法可以添加选项UIViewAnimationOptionAutoreverse | UIViewAnimationOption重复到这个animation序列? [UIView animateWithDuration:1.0f animations:^{ someView.frame = someFrame1; } completion:^(BOOL finished) { [UIView animateWithDuration:0.5f animations:^{ someView.frame = someFrame2; } completion:nil]; }];

UIViewanimation跳转开始

我正在运行这个代码… [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ CGAffineTransform settingsTransform = CGAffineTransformMakeTranslation(self.settingsView.frame.size.width, 0); CGAffineTransform speedTransform = CGAffineTransformMakeTranslation(-self.speedView.frame.size.width, 0); self.settingsView.transform = settingsTransform; self.speedView.transform = speedTransform; } completion:nil]; 但是当它运行的时候,视图在相反的方向上跳过一半的变换,然后在正确的方向滑动到一半的位置。 我已经减慢了animation的持续时间到5秒,但最初的跳转是瞬间的,一半是在错误的方向转换。 当我用这个代码animation回来… [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.settingsView.transform = CGAffineTransformIdentity; self.speedView.transform = CGAffineTransformIdentity; } completion:nil]; 它完全一样的东西。 结果是最后的运动是所需变换的一半,因为它首先在错误的方向上跳变了一半。 我真的不知道为什么会发生这种情况? 有任何想法吗。 ::编辑:: 清除一些可能的歧义。 我并没有试图将这些观点“反弹回”他们所在的位置。 我的animation视图就像屏幕边缘的控制面板。 当用户按下“去”视图,然后滑出。 当用户按下“停止”时,面板滑回到视图中。 至less他们曾经这样做过。 由于启用自动布局(我需要的应用程序的其他部分),我不能只是改变视图的框架,所以我去了变换路线。 通过将视图粘贴到视图控制器和button来运行animation,可以看到这种效果。 谢谢

如何在Swift中加载GIF图像?

我有一个string与我需要放入应用程序的GIF旗帜的URL。 我的代码: func showAdd(){ Request.get("http://www.kyst.no/api/?apiMode=advertisement&lang=no", { (error: NSError?, data: NSData, text: NSString?) -> () in let jsonResult: Dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as Dictionary<String, AnyObject> var banner : NSString = jsonResult["advertisement"]!["banner"] as NSString self.addViewImage.image = UIImage.animatedImageNamed(banner, duration: 1) }) } 但没有任何反应。 请帮忙。