在单个视图控制器中重新加载相同的视图

发布于 2024-12-11 09:18:43 字数 374 浏览 0 评论 0原文

我在 UIViewController 中创建了一个 UIView (我们称之为“Person”),它接受一个 NSArray 的人物并简单地显示有关他们的信息。

该控制器从多个位置(搜索、构建布局等)实例化并作为子视图加载,因此它必须是独立的,没有任何代码来自父/超级视图。

现在,通过向左或向右滑动,我可以在数组中递增/递减并更新各种标签。

这工作得很好,但不是很令人愉悦。我想知道是否可以创建我的视图的另一个实例,重新加载我的标签,然后使用一些动画切换到它?

如果我以错误的方式处理这个问题,我很抱歉,我正在尝试自学 Objective-C。

谢谢,

I've created a single UIView (We'll call it "Person") in an UIViewController that accepts an NSArray of people and simply displays information about them.

This Controller is instanced and loaded as a subview from a variety of places (searches, building layouts..etc...) so it must be self-contained, with none of the code coming from the parent/superview.

Right now, on a left or right swipe, I'm incrementing/decrementing in my array and updating a variety of labels.

This works fine, but isn't very ascetically pleasing. I'm wondering if its possible to create another instance of my view, reload my labels and then switch to it with some animation?

I apologize if I'm going about this the wrong way, I'm attempting to teach myself Objective-C.

Thanks,

Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2024-12-18 09:18:43

是的,你所描述的事情是可以做到的。这是否是实现您想要的效果的最佳方式可能取决于您正在寻找的效果类型。

例如,您也可以选择在视图本身内对数据更改进行动画处理。例如,如果您以动画方式淡出所有标签,更改它们的值,然后将标签淡入淡出,则此效果应该类似于在相同的较大视图的两个实例之间进行转换的效果,并且具有以下优点:内存效率更高,因为您不必创建整个重复视图。

编码也可能会更简单,因为它可以将所有内容保留在单个 UIView 文件中。您提出的解决方案可能需要在视图控制器级别进行一些编码。

对于初学者来说,我会查看 UIView 动画属性,因为它们相对简单。一些更复杂的事情可以用CAAnimation的子类来完成。

Yes, what you are describing is possible to do. Whether or not it is the best way to do what you want probably depends on the type of effect you are looking for.

For example, you do have the option of animating the data changes within the view itself as well. For example, if you animate fading all of your labels out, changing their values, and then fading the labels back in, this effect should look similar to the effect of transitioning between two instances of the same, larger view and has the advantage of being more memory-efficient, since you don't have to create an entire duplicate view.

It will likely be much simpler to code as well, since it can keep everything inside of that single UIView file. Your proposed solution would likely require some coding on the level of the view controllers.

I would look at the UIView animation properties for starters, as they are relatively simple. Some more complex things can be done with the subclasses of CAAnimation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文