- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
谁能准确描述 -[UIScrollView zoomToRect:animated:]
的行为?这种方法似乎确实做了一些复杂的事情,但 Apple 的文档非常稀少。
当内容大小在宽度和/或高度上小于 ScrollView 的大小时,此方法出现不可预测的行为。在某些情况下,此方法会导致 ScrollView 在本应为 0 的情况下具有负的内容偏移量。传递略有不同的矩形后,它会将内容偏移量保留为 0,就像我期望的那样。
为了演示这种奇怪的行为,我设置了一个示例项目,其中包含一个大小为 (200, 200) 的 ScrollView ,其中包含一个大小为 (100, 100) 的内容 View 。我希望内容 View 的缩放到 rect ((0, 0), (200, 200)) 应该将内容留在左上角(即什么都不应该发生).但是,它实际上导致内容滚动到 ScrollView 边界的右下角(内容偏移量(-100,-100))。为什么会这样?
这是我的示例项目中的代码:
@implementation RootViewController
- (void)loadView {
self.view = [[UIView alloc] init];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
self.scrollView.delegate = self;
self.scrollView.backgroundColor = [UIColor whiteColor];
self.scrollView.minimumZoomScale = .5;
self.scrollView.maximumZoomScale = 4;
self.contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
self.contentView.backgroundColor = [UIColor redColor];
[self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap)]];
[self.scrollView addSubview:self.contentView];
self.scrollView.contentSize = self.contentView.frame.size;
[self.view addSubview:self.scrollView];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.contentView;
}
- (void)handleTap {
[self.scrollView zoomToRect:CGRectMake(0, 0, 200, 200) animated:YES]; // Try changing to 199, 199 to get completely different behavior
}
@end
感谢您的任何见解!现在我猜测 UIScrollView
并不是为了显示小于其自身大小的内容而设计的。我的用例是,我可能有一个比 ScrollView 宽但高度较短的内容 View ,我需要能够以编程方式滚动到该内容 View 的右端或左端。
最佳答案
除非有人有更好的答案,否则我将得出结论,当生成的 contentSize
小于 时,调用
任一维度的大小。换句话说,如果你想安全的话,内容应该比 ScrollView 大。-zoomToRect:animated:
会产生未定义的结果>bounds
关于ios - -[UIScrollView zoomToRect :animated:] weird behavior when contentSize < bounds. 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23900933/
我有一个 UIViewController 和一个纵向的 iPad xib。当我的 iPad 处于横向并将该 View Controller 放入 UISplitViewController 的详细信
我在 UITableViewCell 中有一个 collectionView。 collectionView 的内容是动态的,因此它的高度也是动态的,tableView 单元格的高度取决于 colle
我正在制作一个启用了分页机制的简单 UICollectionView,一切正常。但是,当滚动到最后一页时,单元格的数量在屏幕上并不完全可见,最后一页包含前一页的一些单元格。 如何扩展 UICollec
我在 UIView 类中使用 UIBezierpath 绘制对话气泡。在 View 类中包含UITextView。我正在使用以下代码来绘制对话气泡。 //BezierPathView.h @inter
我正在开发一个带有甘特图的小型 iPad 应用程序,它将显示过去 25 小时内的事件。我有 5 个缩放级别,每个级别分别为 1 小时、30 分钟、15 分钟、5 分钟和 1 分钟。我的单元格宽度为 3
我需要动态地将文本字段添加到 ScrollView 。我能够做到这一点,添加后我每次都会计算并更新 ScrollView 的内容大小。 更新内容大小后,我可以在屏幕上查看它,一旦编辑文本字段(键盘消失
是否可以使用动画更改 UIScrollView 的 contentSize ,以便大小在特定时间段内减小/增大,例如 UIView.animateWithDuration(0.3, animation
我们面临一个问题,即当弹出窗口内使用 UIActionSheet 样式的alertController 时,弹出窗口大小会发生变化。这是在我们升级代码库 iOS13 后发生的 示例代码:https:/
收到此错误 2017-07-28 20:17:34.636 App[78013:1799389] *** Terminating app due to uncaught exception 'NSIn
我正在将我的应用程序从 Obj-C 转换为 Swift。 我有 UICollectionViewLayout 的子类,它覆盖了已重命名为“prepare”的“prepareForLayout”。到目前
我有 UITableView 和 UITableViewCell,其中包含 UICollectionView,如下: UITableViewCell UITableViewCell UICollect
我在 View 中有一个 UITextField 和一个 UITextView。 场景是这样的: textFieldShouldReturn:UITextField 的方法使 UITextView 成
我正在双击 UIScrollView 中缩放 UIImageView。在 Interface Builder 中设置后工作正常。我在这里看到的神奇之处在于,当我放大/缩小时,scrollView 的
我的 UIViewController 中有 4 个 UIViews,颜色分别为:黄色、绿色、灰色和蓝色。 我还给出了以下自动布局约束: 黄色 View :Top-8-superview, Leadi
我有一个只能水平滚动的 UIScrollView。 ScrollView 固定在屏幕底部。我已将自动布局约束设置为固定高度。我将 contentSize 设置为固定大小。 但是,当我运行该应用程序时,
我有一个 UITableView,它在 UITableView 第一次重新加载后添加了一些数据,但是我无法向下滚动到新数据,如果我滚动我看到了新数据,但它会自动向后滚动,是的,我重新加载了我的 UIT
所以我的 scrollView 的 contentSize 最初等于我的图像的框架,但似乎我缩放得越多,contentSize 就越大。因此,当 scrollView 放大时,它周围有一个巨大的间隙。
为什么 UIScrollView 实例会在委托(delegate) scrollViewDidEndZooming:(UIScrollView *) aScrollView withView:(UIV
我对 UIScrollView 中的 contentSize 属性有点困惑。我的 scrollView 中有一张图像,我正在缩放和平移。我一直在为 contentSize 设置不同的值,但在我看来,输
在我的 View 中,我创建了一个宽度为 320、高度为 70 的 ScrollView 。 响应用户触摸按钮,我展开 ScrollView ,因此它的大小为 380(h) x 320(w)。 代码如
我是一名优秀的程序员,十分优秀!