如何限制xcode iphone上的移动?(How to constraint movement on xcode iphone?)
我有一个对象,我只想在屏幕的后半部分移动它。
我尝试了下面的代码,但它只适用于上半部分
let halfx = self.bounds.midX self.center.x = max(halfx, self.center.x) self.center.x = min(self.superview!.bounds.size.width-halfx,self.center.x) let halfy = self.bounds.midY self.center.y = max(halfy, self.center.y) self.center.y = min(self.superview!.bounds.size.width/2.0-halfy,self.center.y)I have got an object and I only want to move it in the second half of the screen.
I tried the code below but it only works for top half
let halfx = self.bounds.midX self.center.x = max(halfx, self.center.x) self.center.x = min(self.superview!.bounds.size.width-halfx,self.center.x) let halfy = self.bounds.midY self.center.y = max(halfy, self.center.y) self.center.y = min(self.superview!.bounds.size.width/2.0-halfy,self.center.y)最满意答案
你可以在底部创建一个容器视图,然后你可以把你的图像放在这个容器视图中。 这意味着你的图像永远不会离开它的容器。
You could create a container view thats on the bottom, then you can put your image in this container view. This means that your image can never get out of its container.
更多推荐
发布评论