【问题标题】:how to support rotate in the textbox created by code?如何在代码创建的文本框中支持旋转?
【发布时间】:2012-04-18 06:11:33
【问题描述】:

我在 Xcode 中通过代码创建了一个文本框,通过给

if (isLandScape) {
    textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(800, 10, 200, 30)];
}
else {
    textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(550, 10, 200, 30)];
}

但是当旋转时,会创建两个盒子,我不想要这个,我的代码是怎么处理的?

【问题讨论】:

    标签: objective-c ios xcode


    【解决方案1】:
    1. 查看 autoresizingMask 属性。
    2. 您用什么方法创建这个视图?

    【讨论】:

    • @denish 我尝试关注此链接stackoverflow.com/questions/843683/…,但 xcode 无法识别 NSView,我认为这不适用于 IOS,我是 autoresizingMask 的新手,我从 shouldAutorotateToInterfaceOrientation 方法调用此方法。
    • 在你的情况下 authoresizingMask 应该是 UIViewAutoresizingFlexibleLeftMargin 因此你正在调整你的 x 帧。所以在 viewDidLoad 中: 1. 为当前方向选择合适的框架 2. 创建 UItextField 3. 设置 autoresizingMask = UIViewAutoresizingFlexibleLeftMargin 现在所有的旋转框架调整将自动进行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    相关资源
    最近更新 更多