- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我声明了一个 UILabel!名为“textLabel”,具有上升的重力效果。现在,当它达到 -30 时,我希望标签重新出现在 (200, 444) 处。我使用 NSTimer 检查 if (labelText > -30) 但是当它到达/通过该点时,它只是在它应该出现的地方(在中间附近)闪烁,但它不是从中间开始的。这是我的大部分代码。
如何让标 checkout 现在它的新位置?所以它可以在达到 y 轴上的 -30 后再次循环?我找了又找。帮助PPPPPP
@IBOutlet weak var textLabel: UILabel!
var gravity: UIGravityBehavior!
var animator: UIDynamicAnimator!
var itemBehavior: UIDynamicItemBehavior!
var boundaryTimer = NSTimer()
Override func viewDidLoad() {
animator = UIDynamicAnimator(referenceView: view)
gravity = UIGravityBehavior(items: [textLabel])
animator.addBehavior(gravity)
boundaryTimer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "leftBoundary", userInfo: nil, repeats: true)
itemBehavior = UIDynamicItemBehavior(items: [textLabel])
itemBehavior.elasticity = 1.2
gravity.gravityDirection = CGVectorMake(0.0 , -0.01)
animator.addBehavior(itemBehavior)
}
func leftBoundary() {
if textLabel.center.y < 40 {
self.textLabel.center = CGPointMake(200, 444)
}
}
最佳答案
您可以添加然后删除附件行为,而不是设置中心
,例如:
func leftBoundary() {
if textLabel.center.y < 40 {
let attachment = UIAttachmentBehavior(item: textLabel, attachedToAnchor: textLabel.center)
animator.addBehavior(attachment)
attachment.anchorPoint = view.center
attachment.action = {[unowned self, attachment] in
if self.textLabel.center.y > 100 {
self.animator.removeBehavior(attachment)
}
}
}
}
请注意,您可能希望更改 itemBehavior
,使 allowRotation
为 false
(取决于您所需的 UI)。
另请注意,我在这里使用的这个action
也可以用于您的gravity
行为。因此,不要使用计时器(它可能不会总是同时捕获标签),而是使用 action
,它会在动画的每一帧上调用。
关于ios - swift :我 super 困惑! UILabel 上的 UIGravityBehavior vs NSTimer vs CGPointMake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745672/
谁能给我解释一下 CGPointMake 是做什么的? image.position = CGPointMake(80,200); id go = [MoveTo actionWithDurat
我最近接触了 swift。 一个问题,什么时候用CGPoint,什么时候用CGPointMake? 我交换了这两个语句,它们都返回了相同的结果 self.anchorPoint = CGPoint
如何在Swift中使用CGPointMake?有没有等价物?我收到一个错误: Use of unresolved identifier 'CGPointMake' 基本上,我正在尝试为 Sprite
这个问题已经有答案了: CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero is unavailable in Swift (11
我从 Crashlytics 收到此错误。 Fatal Exception NSRangeException * -[__NSArrayM objectAtIndex:]: index 0 beyon
这个问题在这里已经有了答案: CGRectMake, CGPointMake, CGSizeMake, CGRectZero, CGPointZero is unavailable in Swift
我正在使用 locationInView 来设置用户释放按钮时的位置。释放后,我给出了之前存储的位置,但实际上,我的按钮并没有回到正确的位置。 这是我的代码: - (IBAction)handlePa
我在 YouTube 上观看了有关制作 Flappy Bird 克隆版的教程。使用的代码CGPointMake()用一个整数变量和一个计时器在屏幕上上下移动小鸟,但我复制的代码不会导致小鸟移动。 Vi
我想移动一个 UIImageView,我已经在 Objective-C 中做了这个并且它完全有效。这是代码: tank.center = CGPointMake(tank.center.x + Tan
在Cocos2d中,很多事情都需要一个..点。或者位置。我同时使用了 ccp 和 CGPointMake 方法,这两种方法对我来说都很好用。 但是,我在一些教程中看到,人们在所有示例中都使用其中一个或
我想构建一个类似斯诺克的游戏,一开始我已经遇到了一些问题。我想先建四面墙(这将是 screen-self.frame 的大小),我做的第一面是这样的: let ground = SKNode() gr
将代码转换为最新的 swift 3.0 后,我收到此错误。 还告诉我 CGSize = CGSizeMake(0,0) 的解决方案 static var frameAtStartOfPan: CGRe
将代码转换为最新的 swift 3.0 后,我收到此错误。 还告诉我 CGSize = CGSizeMake(0,0) 的解决方案 static var frameAtStartOfPan: CGRe
将代码转换为最新的 swift 3.0 后,我收到此错误。 还告诉我 CGSize = CGSizeMake(0,0) 的解决方案 static var frameAtStartOfPan: CGRe
将代码转换为最新的 swift 3.0 后,我看到了这个错误。 同时告诉我 CGSize = CGSizeMake(0,0) 的解决方案 static var frameAtStartOfPan: C
所以我声明了一个 UILabel!名为“textLabel”,具有上升的重力效果。现在,当它达到 -30 时,我希望标签重新出现在 (200, 444) 处。我使用 NSTimer 检查 if (la
我收到了 CGPointMake() 的错误消息 /Users/MNurdin/Documents/iOS/RevivalxSwiftSlider/RevivalxSwiftSlider/RangeS
我是一名优秀的程序员,十分优秀!