【发布时间】:2015-04-23 23:18:47
【问题描述】:
我需要能够在某个 CGPoint 创建和显示 UIView。
到目前为止,我有一个手势识别器,它作为子视图添加到主视图中。
然后我以编程方式创建一个 UIView 并将它的 x 和 y 坐标设置为我从手势识别器获得的 CGPoint。
我可以创建它并将其添加为子视图,但创建的 UIView 的位置与 TAP 的位置不同。
AnimationView 子类 UIView
我的代码在下面
tappedLocation = gesture.locationInView(self.view)
var animationImage: AnimationView = AnimationView()
animationImage.frame = CGRectMake(tappedLocation.x, tappedLocation.y, 64, 64)
animationImage.contentMode = UIViewContentMode.ScaleAspectFill
self.view.addSubview(animationImage)
animationImage.addFadeAnimation(removedOnCompletion: true)
是不是我做错了什么?
【问题讨论】:
-
不同是什么意思?完全是另一个位置或附近?
-
事实证明,经过仔细检查,它会在水龙头的位置创建左角的视图。我猜这是水龙头的 x + y 坐标。如何使视图直接在水龙头的中心产生。