我在我的电视应用程序中有一个UITextView
,当我尝试使其可聚焦时,UI不会使其可聚焦,我无法滚动它。我读了一些关于它的问题,有些人说它是一个已知的问题,我们应该使用故事板。实际上我正在使用故事板但仍然无法使其工作。我也尝试使它成为selectable
,scrollEnabled
和userInteractionEnabled
然后最后也尝试了这行代码,但它们都没有工作。
descriptionLbl.panGestureRecognizer.allowedTouchTypes = [NSNumber(integer: UITouchType.Direct.rawValue)]
我也尝试打印qazxsw poi的qazxsw poi和qazxsw poi,这里是日志
bounds
这是我的代码可以帮助我一些身体
contentSize
我想我不应该做这么多技巧,但它不会以任何方式工作。焦点实际上是来到UITextView
但它不滚动。有任何想法吗?
我相信你想要间接,而不是直接接触。以下是我如何设置可聚焦,可滚动的UITextView:
Content Size (740.0, 914.0)
Bounds (25.0, 0.0, 740.0, 561.0)
在Swift 2.1中,这对我有用:
@IBOutlet weak var descriptionLbl: UITextView!
var currentModel : Model?
override func viewDidLoad() {
super.viewDidLoad()
descriptionLbl.selectable = true
descriptionLbl.scrollEnabled = true
descriptionLbl.userInteractionEnabled = true
descriptionLbl.panGestureRecognizer.allowedTouchTypes = [NSNumber(integer: UITouchType.Direct.rawValue)]
descriptionLbl.text = (currentModel?.description)! + (currentModel?.description)! + (currentModel?.description)!
descriptionLbl?.contentInset = UIEdgeInsets(top: 0.0, left: -25.0, bottom: 0.0, right: 0.0);
}
希望能帮助到你。
基于之前的答案,以下是Swift 3.0.1中对我有用的内容:
UITextView
来覆盖self.selectable = YES;
self.userInteractionEnabled = YES;
self.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)];
以返回myTextView.userInteractionEnabled = true
myTextView.selectable = true
myTextView.scrollEnabled = true
myTextView.panGestureRecognizer.allowedTouchTypes = [UITouchType.Indirect.rawValue]
UITextView
canBecomeFocused
- 在Interface Builder中设置它似乎不够true
也可以我找到的其他一些细节:
panGestureRecognizer.allowedTouchTypes = [NSNumber(value: UITouchType.indirect.rawValue)]
使滚动感觉更自然(必须在代码中设置; IB设置不受尊重)isUserInteractionEnabled = true
必须在代码中设置; IB设置不受尊重isScrollEnabled = true
以更改背景颜色以直观地指示焦点。对于Swift 4,这对我有用:
bounces = true
如果您使用objective-C来执行此操作,那将是非常示例:
showsVerticalScrollIndicator = true
以上这些就足够了,但是,如果你使用swift来做这件事,它就行不通了。