Tag: 核心animation

在UITextField底部绘制虚线

我试图在UITextField底部画一条虚线,但没有成功。 以下是我到目前为止所尝试的。 请指导。 func addDashedBorder() { let color = UIColor.white.cgColor let width = CGFloat(2.0) let shapeLayer:CAShapeLayer = CAShapeLayer() let frameSize = self.frame.size let shapeRect = CGRect(x: 0, y: frameSize.height, width: frameSize.width, height: 2.0) shapeLayer.bounds = shapeRect shapeLayer.position = CGPoint(x: frameSize.width/2, y: frameSize.height – width) shapeLayer.fillColor = UIColor.darkGray.cgColor shapeLayer.strokeColor = color shapeLayer.lineWidth = 2.0 // shapeLayer.lineJoin […]

dynamic修改CAKeyframeAnimation的持续时间

在我的代码中,我创build一个无限重复计数CAKeyframeanimation,将其添加到特定的CALayer。 我想在animation的同时修改animation的持续时间(=速度),而不需要重新启动我的animation。 所以当我点击一个button,我得到一个持续时间,我可以为animation设置。 我必须删除animation,创build另一个animation,并使其开始停止。 问题是,我似乎无法从这一点重新启动它,而没有从这一点做出循环。 如果是轮换,这不会有问题,但我使用翻译。 所以,我有3分,A,然后B,然后C,在一条直线上。 我的翻译从A到C,经过B,并且无限重复。 当我改变持续时间,在B点,我只能重build从B到C(这是不好的)翻译animation,或者,我可以重新创build一个animation从A到C与新的时间,但它重新从点A这也不好)。 你有什么想法,我怎么能做我想要的? 谢谢

UIImageViewanimation无法正常工作

我想通过animation使UIImageView的宽度更大。 我有一个UIView和在故事板上制作的UIImageView。 我想要达到的目的是看起来像是从左到右的缩放,并保持原来的位置。 我已经尝试了下面的代码,但它所做的是从其父视图的左上angularanimation图像视图,并移动和缩放它,直到它到达位置并从头开始缩放。 [UIView animateWithDuration:4.0f delay:1.0f options:UIViewAnimationCurveEaseOut animations:^{ CGRect currentFrame = self.imageview1.frame; currentFrame.size.width = 150; self.imageview1.frame = currentFrame; }completion:nil]; 任何想法为什么这种行为?

多次旋转图像并停止在所需的程度?

我已经尝试了各种方法,并不知道如何实现这一点。我在互联网上search了很多,但无法弄清楚。 我有一个ImageView (一个旋转的轮子),我想旋转360度10次(这只是给用户快速转动的感觉),然后我想要旋转它的特定值说90度(但可能会有所不同)。 在这个animation完成后,我想把ImageView带回到初始位置。 我如何做到这一点? 提前致谢。

当有很多使用阴影的UILabels运行的UIViewanimation时,设备会冻结,然后按Homebutton

我在应用程序中遇到了一些问题。 当我在屏幕上有很多图标(UIViews),每个运行一个animation时发生错误。 该屏幕提醒跳板屏幕,并且animation视觉也相似。 所以,如果我按主页button,应用程序不会去背景,我什么都不能做。 即使电源button不起作用。 图标继续晃动。 如果我删除了标签创build方法的调用,则不会发生这种情况。 有什么build议? 谢谢! animation方法(从Three20 api中提取): – (void)wobble { static BOOL wobblesLeft = NO; if (isEditing) { CGFloat rotation = (kWobbleRadians * M_PI) / 180.0; CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation); CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation); [UIView beginAnimations:nil context:nil]; NSInteger i = 0; NSInteger nWobblyButtons = 0; for(Icon *ic in iconList) { ++nWobblyButtons; […]

IOS:用UIImageViewanimation

我有两个imageViews,我称之为firstView和secondView; 我必须做一个animation,移动第三个imageView,我称之为imageView3。 这imageView3里面firstView,我做这个代码 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [imageView3 setFrame:frameinSecondView]; [UIView commitAnimations]; //[imageView3 removeFromSuperview]; //[secondView addSubview:imageView3]; 与此代码,我可以将imageView3移动到secondView,但问题是,我无法设置imageView3在正确的框架“frameinSeconView”; 相反,如果我使用评论的代码 [imageToMove removeFromSuperview]; [scrollViewAlfabeto addSubview:imageToMove]; imageView3进入正确的框架,但我没有看到animation,因为当它开始animation时,imageview3消失从firstView广告出现时,它进入secondView 我怎样才能解决有一个正确的animation,这两个imageViews之间有一个正确的框架。

iOS – 使用两个不同的UIButtons左右旋转图层

我使用CALayer创build了一个图层,并使用旋转animation使用CABasicanimation为其创build了一个图层,并创build了两个TouchDown UIButtons来左右旋转它,当图层旋转到右侧时,出现问题,它恢复到原始angular度,左旋 这是我的代码: -(void)viewDidLoad { //Button 1 UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; aButton.frame = CGRectMake(0, 0, 145, 145); aButton.center = CGPointMake(90, 190); aButton.backgroundColor = [UIColor redColor]; [aButton addTarget:self action:@selector(holdDown) forControlEvents:UIControlEventTouchDown]; [aButton addTarget:self action:@selector(holdRelease) forControlEvents:UIControlEventTouchUpOutside]; [aButton addTarget:self action:@selector(holdRelease) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:aButton]; //Button 2 UIButton *bButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; bButton.frame = CGRectMake(0, 0, 145, 145); bButton.center = […]

如何在iOS上以最高FPS的图像数组来组装animation?

如果这个问题听起来很愚蠢,我很抱歉。 我有一个由另一个项目生成的图像数组,我想尽可能快地将它们显示在屏幕上,将它们组装成animation。 我应该如何做到这一点,以达到帧率至less高于30FPS? 我是iOS开发新手,我不知道从哪里开始。 我应该看看核心animation或OpenGL或Quartz2D或其他? 有人可以指点我一个方向吗? 非常感谢! 真的很感谢帮助。

核心animation – 修改animation属性

我有animation func startRotate360() { let rotation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.z") rotation.fromValue = 0 rotation.toValue = Double.pi * 2 rotation.duration = 1 rotation.isCumulative = true rotation.repeatCount = Float.greatestFiniteMagnitude self.layer.add(rotation, forKey: "rotationAnimation") } 我想要的是通过设置其重复次数为1来停止animation的能力,所以它完成当前的旋转(简单地移除animation是不好的,因为它看起来不好) 我尝试跟随 func stopRotate360() { self.layer.animation(forKey: "rotationAnimation")?.repeatCount = 1 } 但是我碰到了,并在控制台 试图修改只读animation 如何访问可写属性?

确定animation时的约束常量

我有一个视图控制器的顶部和底部视图设置如下: —————- | | | | | | | | —————- < constraint with constant of 250 | | | | | | | | —————- 在IB中使用AutoLayout,我将每个视图设置为符合父级的外部,并给定中心约束250的常量。 然后我有一个IBOutlet我可以animation的中心约束: // MARK: – View Containers @IBOutlet weak public var topView: UIView! @IBOutlet weak public var bottomView: UIView! // MARK: – Constraints @IBOutlet weak var splitViewDividerConstraint: NSLayoutConstraint! 和animation: […]