简体   繁体   English

默认情况下,为什么手势识别器插座很强

[英]Why gesture recognizer outlets are strong by default

When you create an outlet for a control by Ctrl-dragging in Interface Builder it usually suggests to make the outlet weak. 当您在Interface Builder中通过Ctrl拖动为控件创建插座时,通常会建议使插座变弱。

But if you create an outlet for a gesture recognizer the suggestion is to make it strong. 但是如果你为手势识别器创建了一个插座,那么建议就是强化它。 I am curious what is the reason behind of this, what is wrong with making gesture recognizer outlets weak too? 我很好奇这背后的原因是什么,使手势识别器出口的弱点是什么?

ref: http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=5126 参考: http ://www.raywenderlich.com/forums/viewtopic.php?f = 2& t = 5126

From ios 5.0 it does not retain the gesture recognizers when added to a view controller. 从ios 5.0开始,它在添加到视图控制器时不会保留手势识别器。

By making strong properties and connecting them to the gesture recognizers, you can ensure that they stay alive otherwise the app will crash. 通过制作强大的属性并将它们连接到手势识别器,您可以确保它们保持活力,否则应用程序将崩溃。

Credit to Ray Wenderlich team member Hollance . 感谢Ray Wenderlich团队成员Hollance

It's due to a bug in UIKit. 这是由于UIKit中的一个错误。 If you change that to weak, it will crash the app 如果您将其更改为弱,则会使应用程序崩溃

From https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/addGestureRecognizer : 来自https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/addGestureRecognizer

Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. 将手势识别器附加到视图定义了所表示的手势的范围,使其接收对该视图及其所有子视图进行了测试的触摸。 The view establishes a strong reference to the gesture recognizer. 该视图建立了对手势识别器的引用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM