有没有办法以编程方式更新帧(Swift) [英] Is there a way to programmatically update frames (Swift)

查看:92
本文介绍了有没有办法以编程方式更新帧(Swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像在界面生成器中一样以编程方式更新框架?我的某些对象由于动画而放错了位置(我想我还是想修复它),但是它让我想到了前面提到的问题

Is it possible to update the frames like in the interface builder but programmatically? Some of my objects get misplaced because of an animation (which I'll want to fix anyway, I guess..) but it brought to mind the aforementioned question

我已经做了一些谷歌搜索以及在stackoverflow上查找,但是没有找到我想要的内容. 我想将某些按钮的框架更新回我在界面构建器中设置的约束. 很抱歉,如果这个问题太简单了,但我只是在寻找一个简单的答案:是或否+代码行或要调用的方法.它可能甚至不会在我的最终项目中结束;我很好奇.

I have done some googling as well as looking on stackoverflow and not found what I'm looking for. I want to update the frames of some buttons back to the constraints I set in the interface builder. Sorry if this is too simple of a question, but I'm just looking for a simple answer: yes or no + line of code or the method to call. it probably won't even end up in my final project; I'm just curious.

这是一些代码,因为我想这会有所帮助:

Here's some code, since I guess that would help:

@IBAction func optionsButtonPushed(sender: AnyObject) {

    UIView.animateWithDuration(2, animations: {
        var theFrame = self.optionsMenu.frame
        theFrame.size.height += 100
        self.optionsMenu.frame  = theFrame
    })
}

我想,由于动画的原因,位于我正在滚动的视图中的按钮(从零高度开始)消失了,所以可能有比我想的更好的方法 (对不起,这个问题太疯狂了;这是我的第一个问题!)

The buttons located in the view I'm rolling in (from a height of zero) disappear because of the animation, I guess, so there's probably a better way than what I'm thinking (sorry this question is so crazy; it's my first one!)

推荐答案

您可以禁用自动布局.从情节提要.如果仍然要使用自动版式,请使用-viewDidLayoutSubviews方法.

You can disable auto-layout. from storyboard. IF you still want to use AutoLayout then use -viewDidLayoutSubviews method.

self.yourButton.translatesAutoresizingMaskIntoConstraints = YES;

self.yourButton.frame = CGRectMake(16, 133, 130, 130);

这篇关于有没有办法以编程方式更新帧(Swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆