How to design a UIview which will work for both Landscape and Portrait modes?

北战南征 提交于 2019-12-12 04:36:01

问题


I have developed all views for my application in portrait mode, Now we are planning to give user flexibility to change between portrait and landscape mode, I have read some documentation related to that, in which they have given option to adjust controls position (X,Y) in xib based on the orientation, but it will not enough in some case, I need to make a new column because landscape will have more width compared to portrait in such cases, Do I need to make new view? or Is there any way to handle?

Thanks,


回答1:


This question is pretty wide open. It really depends on the design you've chosen and what you are trying to accomplish. For some views, they can easily be reused simply by setting the UIViewAutoresizingMask properly. This will stretch or shrink it, or stick to a margin when its parent is resized. You can also override layoutSubviews to have even more control over what a view's subviews will do when it changes size. Another design is to go even a level higher and use two different ViewControllers: one for each orientation with entirely different views. When the device rotates, the controllers swap their views in some sort of fancy transition. So you see you have a variety of options.




回答2:


i think for simple designs you can you uiautoresizingmask for use orientation method for change frames of controls



来源:https://stackoverflow.com/questions/13392230/how-to-design-a-uiview-which-will-work-for-both-landscape-and-portrait-modes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!