- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我更喜欢禁用 autoresizesSubviews
并使用 setFrame
来放置我所有的 subview 。从 iOS 6 开始,事情似乎发生了很大变化。当我在 viewDidLoad
中的 View 上调用 setFrame 时,没有任何效果。我从 viewWillAppear
尝试过;同样的事情。
setFrame 调用将在 willAnimateRotationToInterfaceOrientation
中工作,但最初不会像在 iOS 5 中那样调用它。
有人可以澄清一下我应该从哪里布局我的 View 吗?
最佳答案
我猜你想从 UIViewController 布局你的 View 。您是否尝试过在 viewDidLayoutSubviews 中执行您的布局任务? :
- (void)viewDidLayoutSubviews
根据 Apple 的文档:
Your view controller can override this method to make changes after the view lays out its subviews.
由于您的 View 本身不对其 subview 进行布局(您不使用自动调整大小、自动布局或 layoutSubViews:),因此您可以在此方法中完成布局任务。
不过,优雅的方法是使用自定义父 UIView 并在那里执行所有布局,覆盖 UIView 的 layoutSubViews:
(除非您动态添加/删除 View )。引自 Apple 关于 "How View Controllers Participate in the View Layout Process" 的文档:
Ideally, the views themselves perform all of the necessary work to reposition themselves, without requiring the view controller to participate in the process at all. However, if the view controller adds and removes views dynamically, a static layout in Interface Builder may not be possible. In this case, the view controller is a good place to control the process, because often the views themselves only have a limited picture of the other views in the scene.
关于iOS:setFrame 不再适用于 viewDidLoad 或 viewWillAppear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645248/
在使用 setFrame 重新绘制框架后,我的转换不绘制。 我在使用 setFrame 更改方向时缩放 View 。但此 View 还需要根据 BOOL 参数更改位置:On = 在 View 中向上,
我尝试在我的 NSWindow 上调用 setFrame:display:animate: 并且没有执行任何操作,但是如果我在同一个窗口上调用 setFrame:display:,它有效。 我需要做其
我为同一 View 多次调用 setFrames。 例如,在设置 ltr View 框架后,我检查布局是否应为 rtl 并再次更改 View 框架。 -(void)setViewsFrames:(BO
我使用下面的代码来设置 iOS 设备上方向发生变化时的 View 。这可以给我想要的形状(更宽和相同的高度),但是改变方向时动画会跳跃。如果我隐藏 setFrame 代码,动画将非常平滑,但形状当然不
我有一个应用程序不会在 -init 和 -viewWillLayoutSubviews 方法之外设置框架的问题。当点击 editButton 时应该发生的是一个隐藏编辑器 View 的动画。尽管如此,
所以我正在为一个更大的项目测试 JSlider,但无法让它工作。 slider 应该调整圆的大小,但它不起作用。我想我可能在创建圆时遇到问题,我正在尝试使用 setFrame,但它给出了一个错误,指出
我正在尝试向 tableviewheader 添加分段控件。我正在使用以下代码来做到这一点 UISegmentedControl *segmentedControl = [[UISegmentedCo
我从我的应用程序收到此崩溃报告,这似乎是在滚动 UICollectionView 时发生的。这是一个很少发生的崩溃,当我设法在 Xcode 中捕获它时,也不知道是哪段代码导致了它。我的 UIColle
在我的 Swift 项目中,我使用了 obj-c 框架。到目前为止它工作正常,但我正在尝试将一些在 obj-c 上编写的旧代码转换为 Swift。 除了这行代码,我设法翻译了所有内容: [[self.
您好,我有一段代码只有一行不起作用... [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEas
我想确保我的 View 都没有错位,因此我想在所有 uiview 上设置框架时使用 CGRectIntegral。但我不想让所有开发人员都像他们通常那样设置框架(例如 view.frame = aCG
在我的应用程序中,我需要一次显示同一 NIB 的多个窗口,并且它将根据计时器关闭/释放, 一切工作正常,除了窗口位置。我的要求是,它应该将窗口显示在前一个窗口的正下方,如果存在相同 NIB 的任何窗口
全部。当我使用 NSTableView 时,只要到达这个函数就会出现以下错误。 -(id)tableView:(NSTableView *)tableView viewForTableColumn:(
我想将图像放置在位置 (10,10,60,60)。我编写了代码,但图像从角落显示。代码 [cell.imageView setFrame:CGRectMake(10,10,60,60)]; 无效。 i
我目前正在调试我们的应用程序中的一个问题,UITextView 的最后几行被切断。 UITextView 位于 collectionView 单元格内,该单元格允许其自身折叠。我试图在框架更改时捕获文
这是我第一次以编程方式添加 UI 元素。该应用因错误而崩溃: 2014-01-14 18:39:50.080 Convention[27580:70b] -[__NSCFConstantString
我正在尝试像这样将 AVCaptureVideoPreviewLayer 添加到我的 View 中 [captureVideoPreviewLayer setFrame:CGRectMake(10.0
我正在尝试根据标签中的文本量更改 UILabel 的高度。 我可以计算标签所需的大小,但是当我尝试设置 UILabel 框架时,它并没有改变。 下面是我的代码。即使我将最后一行中的 size.heig
我有一个正在重构的 Objective-C 项目,我遇到了一行我无法翻译的内容,而且 Apple 的文档站点似乎已关闭: [self.stepperView setFrame:self.stepper
我正在尝试使(10.10 中的新功能)NSSplitViewItem 折叠和展开,同时移动它的包含窗口,以便将整个东西保持在“原位”。 问题是我在动画中出现抽搐(如 here 所示)。 我进行折叠的代
我是一名优秀的程序员,十分优秀!