iOS UIScrollView 与 UIImageView 旋转方面问题
对于我缺乏 iOS SDK 知识,我提前表示歉意,我是一名 Android 开发人员,负责维护和更新 iPhone 应用程序。
我正在使用 UIScrollView 来处理 UIImageView 上显示的图像的缩放和拖动。
UIImageView 中的图像每秒从 Web 服务器请求多次。当设备方向改变时,图像尺寸会更改为当前帧的尺寸,例如,在纵向模式下使用 iPad 时,图像尺寸将为 768x1024,但切换到横向模式时,图像尺寸将为 1024x768。网络服务器根据我请求的图像的方向和纵横比,向图像的顶部/底部或左侧/右侧添加黑条。
我的问题是,旋转设备后 UIImageView 永远不会按照我期望的方式运行。我的预期行为是 UIScrollView 将继续执行其滚动操作,但在旋转后将其基本视图重置为新框架尺寸的视图。
如果我没有为 UIScrollView 指定 contentMode,则图像会显得被压扁,就好像 ScrollView 试图以先前的方向尺寸显示图像一样。
如果我为 ScrollView 指定 UIViewContentModeScaleAspectFit 的 contentMode 并一直缩小,则图像看起来比视图小,纵横比是正确的,但图像居中且高度是之前方向的高度。
如果我为 ScrollView 指定 UIViewContentModeScaleAspectFill 的 contentMode,则一切都会正确显示,但由于当我退出滚动视图时,视图实际上会缩放图像以适合屏幕,因此我使用的缩放数据无法正确转换。
当设备方向更改时,我需要做什么才能将 UIScrollView 的“基本尺寸”设置为新的框架尺寸?或者我是否缺少需要设置的属性?
I apologize in advance for my lack of iOS SDK knowledge, I am an Android developer that has been tasked with maintaining and updating an iPhone application.
I am using a UIScrollView to handle zooming and dragging of an image that is being displayed on a UIImageView.
The image in the UIImageView is requested from a web server multiple times a second. When the orientation of the device changes the image dimensions change to that of the current frame, for example when using an iPad in portrait mode the image dimensions will be 768x1024 but when switching to landscape mode the dimensions of the image will be 1024x768. The webserver does the work of adding black bars to the top/bottom or left/right of the image depending on the orientation and aspect ratio of the image I am requesting.
My problem is that after rotating the device the UIImageView never behaves the way I expect it to. My expected behavior is that the UIScrollView will continue to perform its scrolling actions but reset its base view to that of the new frame dimensions after rotation.
If I don't specify a contentMode for the UIScrollView then the Image appears squished as though the ScrollView is trying to display the image in the previous orientations dimensions.
If I specify a contentMode of UIViewContentModeScaleAspectFit for the ScrollView and zoom all the way out the image appears smaller than the View, the aspect ratio is correct, but the image is centered and the height is that of the previous orientations.
If I specify a contentMode of UIViewContentModeScaleAspectFill for the ScrollView everything appears correctly, but since the View is actually scaling the image up to fit the screen when I exit the scrollView the zoom data that I was using doesn't properly translate over.
What do I need to do to set the "base size" of the UIScrollView to the new frame size when the device orientation has changed? Or am I missing a property that I need to have set?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您可能没有更新滚动视图上的内容大小。
你需要做一些类似的事情
希望就是这样
It sounds like you may not be updating the content size on the scroll view.
You need to do something like
Hope that's it
如果我理解正确的话,您可以在 UIScrollView 中使用
zoomToRect:animated:
方法。然后您可以将缩放设置为图像的大小。If I understand correctly, you can use the
zoomToRect:animated:
method in UIScrollView. You can then set the zoom to the size of the image.