Tag: animatewithduration

UIViewanimation一个约束会影响另一个约束

我有一个UIImageView,我想在后台使用泛效应缓慢animation。 我的背景图片视图有四个约束: 从顶部到顶部布局指南的距离(零) 从底部到底部布局指南的距离(零) 宽度(恒定在850) 引导空间超级查看(零,连接到代码为backgroundImageViewLeftMargin outlet) 图像视图的视图模式设置为“纵横填充”。 当我运行我的应用程序,没有问题,静态图像显示。 我添加下面的代码来animation我的视图: -(void)animateBackgroundHorizontally:(BOOL)forward{ self.backgroundImageViewLeftMargin.constant = forward ? -500 : 0; [self.backgroundImage setNeedsUpdateConstraints]; [UIView animateWithDuration:30 animations:^{ [self.backgroundImage layoutIfNeeded]; } completion:^(BOOL finished) { [self animateBackgroundHorizontally:!forward]; }]; } 然后我调用[self animateBackgroundHorizontally:YES]; 在… viewWillAppear: 。 这是发生了什么事情: 图像从一个意想不到的(但总是相同的)位置开始animation(顶部边缘位于屏幕的中间位置,应该在屏幕的顶部),正确地animation到其最终位置,然后在animation返回到原始位置时位置,它确实animation正确 。 我animation的唯一属性是左边距。 当我不调用animation代码时,它显示正确。 为什么animation从图像上看到的位置不正确? 我试过将self.backgroundImage.translatesAutoresizingMaskIntoConstraints设置为YES (我无法同时满足constaints错误)和NO但它没有工作。 这个问题在iOS 6和iOS 7上都是持久的。

swift UIView animateWithDuration重复和自动反向

我是新手,这是我的第一个问题….我想缩小一个持续2秒的球,然后增长5秒。 我的问题是第二个持续时间被忽略(球收缩2秒,并增长2秒)。 我希望有一个人可以帮助我。 这是我的尝试: let ball = UIView() ball.frame = CGRectMake(50, 50, 50, 50) ball.backgroundColor = UIColor.blueColor() ball.layer.cornerRadius=25 relaxContainer.addSubview(ball) UIView.animateWithDuration(2.0, delay:0, options: [.Repeat, .Autoreverse], animations: { ball.frame = CGRectMake(50, 50, 20, 20) }, completion: { finished in UIView.animateWithDuration(5.0, animations: { ball.frame = CGRectMake(50, 50, 50, 50) }) })

使用具有约束的持续时间的animation快速移动button,并在其中检测触摸

我想将一个button从A点移到B点。A点: leadingConstraint = 120, topConstraint = 400 。 B点: leadingConstraint = 120, topConstraint = 200 。 为了我的游戏目的,我不能使用框架。 我也希望能够在移动时检测到它的触摸(我不知道该怎么做)。 我有这个代码,我试图移动button(使用animation持续时间),但最新发生的是,它从左上angular(小尺寸),而不是从A点开始。然后到B点(正常尺寸)。 这里是代码: @IBAction func Start(sender: UIButton) { var topAnchorforButton: NSLayoutConstraint! let button = UIButton() button.setTitle("button", forState: .Normal) button.setTitleColor(UIColor.blackColor(), forState: .Normal) button.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button) button.translatesAutoresizingMaskIntoConstraints = false topAnchorforButton = button.topAnchor.constraintEqualToAnchor(view.topAnchor, constant: 400) NSLayoutConstraint.activateConstraints([ button.widthAnchor.constraintEqualToConstant(75), button.heightAnchor.constraintEqualToConstant(75), […]

创build一个方法来执行animation,并在目标c中使用信号量等待完成

我想创build一个方法,使用UIView的“+ animateWithDuration:animation:完成”方法来执行animation,并等待完成。 我很清楚,我可以将通常会在完成块后出现的代码放在后面,但是我想避免这种情况,因为之后会有大量的代码,包括更多的animation,这会使我留下嵌套块。 我试图用一个信号量来实现这个方法,但是我不认为这是最好的方法,尤其是因为它实际上并不工作。 任何人都可以告诉我什么是我的代码错误,和/或达到相同目标的最佳方式是什么? +(void)animateAndWaitForCompletionWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations { dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [UIView animateWithDuration:duration animations:animations completion:^(BOOL finished) { dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); } 我不知道我的代码有什么问题,但是当我调用如下所示的方法时,完成块从来没有运行,我最终陷入了僵局。 [Foo animateAndWaitForCompletionWithDuration:0.5 animations:^{ //do stuff }]; – – – – – – – – – – – – – – – – – – – – – -编辑 – – […]