gpt4 book ai didi

objective-c - 自动将 View 放置在下一个逻辑位置(如布局管理器)

转载 作者:行者123 更新时间:2023-11-29 11:22:35 24 4
gpt4 key购买 nike

我正在开发一个 iPad 应用程序,它允许用户选择要在屏幕上显示的“小部件”。屏幕分为两列,小部件将放置在左列或右列中。每个小部件都是一个 View Controller ,具有静态固定宽度,但高度取决于小部件的内容。我正在寻找一种将小部件放置在屏幕上的方法,以便它们自动放置在下一个逻辑位置 - 这类似于 Java 中的布局管理器所做的事情。

我创建了 addWidget 方法,它跟踪每列中所有小部件的高度。然后将小部件添加到具有最小高度的列。这有效,但我正在寻找一种更优雅的方法,或者寻找改进当前解决方案的想法。

- (void) addWidget:(UIViewController *)controller {

if(leftHeight <= rightHeight) {
controller.view.frame = CGRectMake(20.0, leftHeight, controller.view.bounds.size.width, controller.view.bounds.size.height);
leftHeight = leftHeight + controller.view.bounds.size.height + 20;
}

else {
controller.view.frame = CGRectMake(self.view.bounds.size.width-controller.view.bounds.size.width-20, rightHeight, controller.view.bounds.size.width, controller.view.bounds.size.height);
rightHeight = rightHeight + controller.view.bounds.size.height + 20;
}

[scrollView addSubview:controller.view];
}

谢谢

最佳答案

如果您正在为您的小部件寻找类似“跳板”的 View ,我建议查看 Three20框架。

它提供了一个 [TTLauncherView][2] 类,它实现了您正在寻找的东西,包括分页、图标重新排序和删除时的抖动效果——就像真正的 Springboard。一旦您对 Three20 有所了解,它就非常容易使用。

顺便说一句,它是官方 Facebook 应用程序使用的...

如果您不想使用 Three20,您可以简单地查看实现来做出决定。

关于objective-c - 自动将 View 放置在下一个逻辑位置(如布局管理器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6160057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com