简体   繁体   English

在scrollview内放大内容视图不起作用

[英]Zooming on content view inside of scrollview doesn't work

I'm creating a scrollview with content view inside of it. 我正在创建一个带有内容视图的滚动视图。 inside of the content view there are buttons. 内容视图内部有按钮。

from this point, i already can zoom and pan on content view. 从这一点来看,我已经可以缩放和平移内容视图了。 but when the touch happen on a button the scrollview doesn't zoom. 但是当触摸按钮时,滚动视图不会缩放。

I have just had the same problem and solved it with the following steps : 我刚刚遇到了同样的问题,并通过以下步骤解决了这个问题:

  1. Create a UIView. 创建一个UIView。
  2. Create a UITapGestureRecognizer 创建一个UITapGestureRecognizer
  3. Add the UITapGestureRecognizer to the UIView to handle taps. 将UITapGestureRecognizer添加到UIView中以处理轻击。
  4. Create a UIButton. 创建一个UIButton。
  5. Disable User Interaction ( isUserInteractionEnabled = false ) on the button. 禁用按钮上的用户交互( isUserInteractionEnabled = false )。
  6. Add the UIButton as a SubView of the UIView. 将UIButton添加为UIView的子视图。
  7. In the UITapGestureRecognizer tapped selector, handle the UIButton touchesUpInside call. 在UITapGestureRecognizer轻击的选择器中,处理UIButton touchesUpInside调用。
  8. Add the first UIView into the UIScrollView. 将第一个UIView添加到UIScrollView中。
  9. Make sure the UIScrollView delay content touches delaysContentTouches = true 确保UIScrollView延迟内容触摸delaysContentTouches = true

The UIScrollView should be able to now seamlessly zoom and you can respond to your buttons. UIScrollView现在应该能够无缝缩放,并且您可以响应按钮了。

You can skip the button altogether if you want and just handle the Tap in the Gesture Recognizer. 如果需要,可以完全跳过该按钮,而只需在手势识别器中处理“点击”即可。 I had to do it the way above because the buttons were a custom sub classed buttons and had a lot of additional custom rendering and functionality included. 我必须按照上面的方法进行操作,因为这些按钮是自定义子类别的按钮,并且还包含许多其他自定义呈现和功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TouchableOpacity onPress 在 ScrollView 中不起作用 - TouchableOpacity onPress doesn't work inside ScrollView 如果在滚动视图下面有一个视图,则调整滚动视图缩进不起作用 - Adjust scroll view indents doesn't work if there is a view below the scrollview NavigationLink 不适用于 SwiftUI 列表中的 ScrollView - NavigationLink doesn't work with ScrollView inside a List in SwiftUI ScrollView在ViewController中不起作用 - ScrollView doesn't work in ViewController UISearchDisplayController在容器视图中不起作用 - UISearchDisplayController doesn't work inside container view 快速缩放ScrollView内的UIImageView - Zooming UIImageView inside ScrollView in swift Scrollview缩放问题中的UIView - UIView inside a Scrollview zooming issue 垂直滚动视图内的水平滚动视图不起作用 - Horizontal Scroll View inside Vertical Scroll view doesn't work 即使contentSize大于frame并且在设置内容大小之前添加了子视图,scrollView也不起作用 - scrollView doesn't work even though contentSize is larger than frame and subview is added before setting content size 如何在放大滚动视图时将内容视图的特定区域保持在可见框架内? - How to keep specific area of content view within a visible frame while zooming in scrollview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM