感谢上帝,有人提出了更好的回应。我最初使用以下阻止程序构建它,但 userInteractionEnabled BOOL 更容易。
事实证明,这个问题是 UITextView 的一个已知问题。我的解决方法:
#import <UIKit/UIKit.h>
/**
God damn SDK bug means that you can't use editable to enable/disable a
UITextView (It brings up the keyboard when re-enabling)
*/
@interface StupidF_ingTextViewBlocker : UIView {
}
@end
@implementation StupidF_ingTextViewBlocker
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
}
return self;
}
- (void)dealloc {
[super dealloc];
}
@end
然后代替我放在上面的代码(而不是使用可编辑的)。要禁用(假设我有一个名为 blocker 的 iVar):
// Put this in a lazy loading property or in loadView
blocker = [[StupidF_ingTextViewBlocker alloc] initWithFrame:writeView.frame];
// The blocker code ~= textView.editable = NO
[self.view addSubview:blocker];
// Removing the blocker ~= textView.editable = YES
[blocker removeFromSuperView];