设置 xib 文件视图之外的视图以适应滚动视图方向不同的 xib - iOs
我有一个 UIScrollView,其中包含一个视图控制器,其中包含几个控制器 - 文本字段、按钮、图像等...... 当它以纵向模式显示时,我希望它表现得好像没有滚动视图(当然,它仍然存在,但禁用了滚动和弹跳等,内容大小是应用程序框架的大小),并且自定义视图只是正常显示,但当切换到横向时,我想让滚动视图可供使用,以避免紧张的用户界面。
由于本地化原因,我想对纵向/横向模式使用特定的 xib 文件,而不是使用代码以不同的方式放置对象 我这样做时遇到了 3 个问题:
1)我无法找到一种方法在旋转时加载不同的 xib 并将其应用到控制器(我也希望它能够顺利过渡,但现在不那么重要)
2)我找不到在 xib 文件中设置应用程序框架之外的内容的方法(我没有直接在滚动视图中使用按钮等,而是在滚动视图内的自定义视图内),所以我无法放置任何内容在看不见的部分滚动视图(需要滚动才能看到的部分)
3)我找不到通过 xib 文件指定滚动视图内容大小的方法,这是为了使界面像可以进行本地化。
您对如何实现/解决这些需求有什么想法吗?
提前致谢!
I have a UIScrollView which contains a view controller which contains a couple of contorllers - text fields, buttons, an image, etc...
When it is shown on portrait mode, I want it to act as if there is no scroll view ( its still there, of course, but disabled scrolling and bouncing and etc, content size is application frame's size ), and the custom view is just displayed normally, but when switching to landscape I want to make the scroll view available to use in order to avoid tight user interface.
I want to use a specific xib file for portrait/landscape modes and not place the objects differently using code, because of localization reasons
I encountered 3 problems doing this:
1)I cant find a way to load and apply to the controller a different xib when rotating ( I'd like it to be a smooth transition as well, but not as important right now )
2)I can't find a way to set up something beyond the application frame's in a xib file ( I dont have the buttons and etc directly in a scroll view, but inside a custom view which is inside a scroll view ), So I cant place anything on the invisible part of the scroll view ( the part that needs to be scrolled into in order to be seen )
3)I cant find a way to specify a scroll view's content size via a xib file, which is needed in order for the interface to be as flexible as possible for localization.
Do you have any ideas on how to implement/solve these needs?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议做你说你不会做的第一件事:
我花了很多时间尝试使用不同的 XIB 来实现不同的方向,但情况如下:
1)如果你有一个纵向的 UITextField,当你旋转到横向时,你必须确保例如,纵向模式下的文本与横向模式下的文本相同。您必须对每个对象执行此操作。
2)即使你不看第1)点,我也从来没有能够成功地实现两个xibs解决方案。我并不是说你做不到,我只是说根据我的经验,我无法做到这一点。
因此,如果您至少考虑执行 1 xib 解决方案,我可以解释一下:
//为纵向旋转的“oneOfmyViews”创建框架
oneOfMyviews.frame=CGRectMake(...,....,...,...);
}
//为横向旋转的“oneOfmyViews”创建框架
oneOfMyviews.frame=CGRectMake(...,....,...,...);
然后,您可以在viewsPosition 方法中定义视图的框架。你赢了什么?
1)干净的代码。
2)漂亮的过渡。
3) 轻松指定滚动视图的内容大小。
对于您的 UIViews 旋转问题 =>自定义视图控制器 => UIScrollView。
您可以执行以下操作:
1)在 CustomViewController 内的 UIView 的自定义视图(上述方法)中执行完全相同的操作。
2) 在具有 CustomViewController 的视图中,您可以执行以下操作:
这样您将使 customViewController 内的 UIView 旋转。最后一个提示:禁用 autoresize-subviews 并从 UIView 中取出每个自动调整大小(因为您将单独定义它们的框架)。
I would advise doing the first thing you said you wouldn't do:
I have spend a good amount of time trying to use a different XIB for different orientation but here is the deal:
1) If you have an UITextField in Portrait, when you rotate to landscape, you have to be sure that the text in portrait mode is the same in landscape, for example. You have to do that for every object.
2) Even if you dont look to point 1) I was never able to implement the two xibs solution successfully. I am not saying you cant do it, I am just saying from my experience, that I could not achieve that.
So, if you at least think doing the 1 xib solution, I could explain a bit:
//Create the frame for your "oneOfmyViews" for the portrait rotation
oneOfMyviews.frame=CGRectMake(...,....,...,...);
}
//Create the frame for your "oneOfmyViews" for the landscape rotation
oneOfMyviews.frame=CGRectMake(...,....,...,...);
You could then in the viewsPosition methods define your view's frames. What you win?
1) Clean code.
2) Beautiful transitions.
3) Specify your scroll view's content size easily.
For you problem with the rotation of your UIViews => CustomViewController => UIScrollView.
You can do something like this:
1) Do exactly the same thing in your custom view (methods above) for your UIViews inside your CustomViewController.
2) In the view that has your CustomViewControllers you can do the following:
This way you will make the UIViews inside your customViewController rotate. One last tip: disable autoresize-subviews and take out every auto-sizes from your UIViews (because you will be defining their frame individually).