2

我正在为我的应用程序实现一个共享扩展,到目前为止一切都很好,除了我似乎无法关闭使用默认布局/故事板自动打开的键盘。

我保持默认设计/布局(SLComposeServiceViewController),其中包括预览图像和 UITextview,UITextview 自动获得焦点,打开键盘。

通常这很好,但如果你没有登录我的应用程序,我会显示一个 UIAlertController 说你需要登录才能共享。问题是键盘在警报的同时打开。

我已经尝试过在 viewDidLoad、viewDidAppear 和 viewWillAppear 中都没有运气[self.view endEditing:YES];[self.textView resignFirstResponder];

4

2 回答 2

1

找到了答案!我没有仔细阅读文档...

我不得不[self.textView resignFirstResponder];-(void)presentationAnimationDidFinish

于 2015-01-23T22:29:15.610 回答
0

我的方法是使用UITextViewDelegate

- (void)viewDidLoad {
     [super viewDidLoad];
     self.textView.delegate = self;
     self.canShare = NO;
     [self.view setAlpha:0.0];
}

在您的检查登录逻辑中更改canShare为 YES

- (void)checkLoggedIn {
    if ([[ShareAccountManager checkLoggedIn]) {
        self.canShare = YES;
        [self.view setAlpha:1.0];
    }
}

并实现方法textViewShouldBeginEditing

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    if (self.canShare) {
        return YES;
    }
    return NO;
}
于 2017-01-10T09:29:15.547 回答