如何限制xcode iphone上的移动?(How to constraint movement on xcode iphone?)

编程入门 行业动态 更新时间:2024-10-27 08:30:03
如何限制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.

更多推荐

本文发布于:2023-04-27 20:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329041.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iphone   xcode   movement   constraint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!