- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
下面的代码在我第一次从相机胶卷中选择图像时按预期运行。图像被缩小以适应 scrollView。但是当我再次运行它以重新选择图像并再次选择相同的图像时,它会缩放到 1.0 比例。无法弄清楚我需要重置什么才能使它每次都能正常工作。有什么想法吗?
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
scrollView.contentSize = CGSize(width: 0, height: 0)
picView.image = nil
picView.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
picView.removeFromSuperview()
self.dismissViewControllerAnimated(true, completion: nil)
scrollView.addSubview(picView)
scrollView.contentSize = image.size
let scaleWidth = scrollView.frame.size.width / scrollView.contentSize.width //image.size.width
let scaleHeight = scrollView.frame.size.height / scrollView.contentSize.height //image.size.height
let minScale = min(scaleWidth, scaleHeight)
scrollView.minimumZoomScale = minScale
scrollView.maximumZoomScale = 1.0
scrollView.zoomScale = minScale
}
最佳答案
我认为您已经弄清楚了这一点,但我将填补可能缺失的部分。缩放实际上是如何工作的?正如我所说 in my book :
The scroll view zooms by applying a scaling transform to the scalable view... Moreover, the scroll view is concerned to make scrolling continue to work correctly; ... therefore, the scroll view automatically scales its own contentSize to match the current zoomScale.
因此,在开始调整内容大小之前,您需要删除该转换。因此,在您换出 ImageView 之前,预先将 zoomScale
重置为 1 可能就足够了。
更好的是,为什么不把 ImageView 留在那里呢?您似乎在日常工作中做了很多不必要的工作;为什么不将其视为带有 ImageView 内容 View 的 ScrollView ,其中被换出的只是图像?
最后,为什么不使用自动布局呢?这样,图像的大小自动成为 ImageView 的大小, ImageView 的大小自动成为 ScrollView 的内容大小。
关于ios - UIScrollView zoomScale 不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32798630/
我有一个使用 MapKit 的应用程序。 我在调整 map 大小后计算当前缩放比例。 通过定义(来自MKGeometry.h 文件) MKZoomScale provides a conversion
我有一个UIScrollView中的UIImageView。我使用以下代码将图像加载到UIImageView的CALayer中: UIImage *image = [UIImage imageName
我使用 UICollectionView 水平滚动方向创建 PhotoViewer,pagingEnable = true。我创建的 UICollectionViewCell 包含 UIScrollV
下面的代码在我第一次从相机胶卷中选择图像时按预期运行。图像被缩小以适应 scrollView。但是当我再次运行它以重新选择图像并再次选择相同的图像时,它会缩放到 1.0 比例。无法弄清楚我需要重置什么
我刚刚创建了一个动画来放大或缩小 UIScrollView,但我的问题是 ZoomScale 没有更新。例如,我使用创建的动画缩小 UIScrollView 内的 UIView,但是当我使用展开手势放
我的问题是我想检测 UIWebView 的缩放比例,我尝试搜索它但没有得到正确的答案。感谢任何帮助...... 最佳答案 虽然 UIWebView 没有 zoomScale 属性,但 UIScroll
随着 ScrollView ZoomScale 的减小或增大,ScrollView contentOffset.X 和 contentOffset.Y 的最大值分别减小或增大。我们可以通过编程方式推断
当 UIScrollView 放大时,我遇到了一个奇怪的问题。 我们在 iPad 上的 UIScrollView 中显示用户创建的表单,因此字段的大小可以不同。定位似乎可以很好地处理向上移动字段(通过
如果 zoomScale == oldScale,我正在尝试将 newScale 分配给 UIScrollView 的 zoomScale,并且分配 zoomScale = newScale 不起作用
现在我有一个位于 UIScrollView 之外的 View 。由于多种原因,它不能简单地位于 ScrollView 内。所以现在我正在做的是,随着 UIScrollView 的缩放/平移,我更新了我
我有一个自定义的 UIViewController,我在上面添加了一个 UIImageView(在 StoryBoard 上),然后将 UIImageView 嵌入到 UIScrollView 中。我
我有一个扩展的 UIScrollView,它直接取自 Apple 文档示例项目“ZoomingPDFViewer” 如果你得到这个项目,你会注意到它的 UIScrollView 扩展类“PDFScro
我需要在 UIScrollView 上将 zoomScale 设置回 1,但我需要它是动画的。我以为我可以为此使用 CABasicAnimation,但 NSValue 似乎没有“valueForFl
执行摘要:有时 UIScrollView 会对 contentOffset 的值进行不必要的更改,从而导致应用在正在查看的文档中显示错误的位置。不需要的更改与 ScrollView 的 zoomSca
iOS 应用程序相对较新,而且速度很快,所以我对如何进行有点迷茫。 基本上,我有一个 UIImageView,并且我可以捏合来缩放/滚动,因为我的 UIImageView 在 UIScrollView
我的 UIScrollView 在使用 zoomToRect 时没有设置它的 contentOffset。 我有一个 UIScrollView,里面有一个 UIImageView。到目前为止,滚动和缩
在 ScrollView 的委托(delegate)方法 viewForZoomingInScrollView: 中,我做了看似无辜的事情: //scrollView是传递给该方法的参数 float
我写了一些代码来保存 WKWebView 的 ScrollView 的 contentOffset 和 zoomScale,因此它们可以在 webView 加载后恢复。我发现设置这些 scrollVi
我是一名优秀的程序员,十分优秀!