ZoomToRect 奇怪的行为
我在使用 ZoomToRect 函数时遇到问题。我有一个包含视图的滚动视图。当用户单击视图时,我会对其进行缩放。它可以工作,只是当帧的 y 位置高于 2389 时,该函数会缩放到 2389 y 位置处的相应帧。
这是我使用的代码:
-(void) launchZoomInAnimationInView:(UIView*) cellView; {
// Get the rect corresponding to the clicked cell
CGRect zoomedFrame = [self.zoomScrollView convertRect:cellView.frame fromView:cellView.superview];
// Zoom to the rect
[self.zoomScrollView zoomToRect:zoomedFrame animated:YES];
// Display for debugging
[ViewToolkit showFrame:zoomedFrame inView:self.zoomScrollView];
NSLog (@"Zoom on frame %@ with contentSize %f", NSStringFromCGRect(zoomedFrame), self.zoomScrollView.contentSize.height);
}
函数 showframe 向我显示我计算的框架位于正确的位置(我在屏幕上显示一个红色矩形)。
NSLog 显示内容大小足够高:
缩放帧 {{100, 3021.6}, {230.4, 307.2}},内容大小为 10337.759766。
在动画结束时,我显示了滚动视图的边界,它给了我 {{100, 2389}, {768, 1024}},而不是 {{100, 3021.6< /strong>}, {768, 1024}} 我真的不明白。对于任何高于 2389 的值,我总是会得到 2389 y 位置的结束帧。并且当contentSize不同时这个值不会改变。
请注意,在启动此功能之前,我没有更改scrollView的zoomScale。
I'm having a problem with the zoomToRect function. I have a scroll view that contains views. When the user clicks on an view, I launch a zoom into it. It's working except that when the y position of the frame is higher than 2389, the function zoom to the corresponding frame at 2389 y position.
Here is the code I use :
-(void) launchZoomInAnimationInView:(UIView*) cellView; {
// Get the rect corresponding to the clicked cell
CGRect zoomedFrame = [self.zoomScrollView convertRect:cellView.frame fromView:cellView.superview];
// Zoom to the rect
[self.zoomScrollView zoomToRect:zoomedFrame animated:YES];
// Display for debugging
[ViewToolkit showFrame:zoomedFrame inView:self.zoomScrollView];
NSLog (@"Zoom on frame %@ with contentSize %f", NSStringFromCGRect(zoomedFrame), self.zoomScrollView.contentSize.height);
}
The function showframe shows me that the frame I calculated is at a correct position (I display a red rectangle on screen).
The NSLog shows that the content size is high enough :
Zoom on frame {{100, 3021.6}, {230.4, 307.2}} with contentSize 10337.759766.
At the end of the animation, I display the bounds of the scrollView and it gives me {{100, 2389}, {768, 1024}}, instead of {{100, 3021.6}, {768, 1024}}
I really don't get it. For any value above 2389 I always get a ending frame with 2389 y position. And this value doesn't change when the contentSize is different.
Note that before launching this function, I didn't change the zoomScale of the scrollView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是由于我的 viewForZoomingInScrollView 函数返回滚动视图本身,而它应该返回滚动视图的子级。
请在此处查看完整答案:https://devforums.apple.com/message/406487
根据根据Apple论坛上的讨论,Apple API中似乎存在错误,因此我们永远不应该在viewForZoomingInScrollView中返回scrollView。
The problem was due to my viewForZoomingInScrollView function which was returning the scrollview itself while it's supposed to return the child of the scrollView.
See the full answer here : https://devforums.apple.com/message/406487
According to the discussion on Apple forum, it seems there is a bug in Apple API so we should NEVER return the scrollView in viewForZoomingInScrollView.