私は単に私のiMessage AppにUITextField
を使用しようとしています。iMessage App - コンパクトなプレゼンテーションスタイルでUITextFieldを使用する
コンパイルモード(MSMessagesAppPresentationStyleCompact
)でテキストフィールドを選択すると、すべてのビューが消えてしまうという問題があります。拡張モードで正常に動作するようです。
コンパクトモードでテキストフィールドを使用する適切な方法は何ですか?おかげ
私は単に私のiMessage AppにUITextField
を使用しようとしています。iMessage App - コンパクトなプレゼンテーションスタイルでUITextFieldを使用する
コンパイルモード(MSMessagesAppPresentationStyleCompact
)でテキストフィールドを選択すると、すべてのビューが消えてしまうという問題があります。拡張モードで正常に動作するようです。
コンパクトモードでテキストフィールドを使用する適切な方法は何ですか?おかげ
拡張モードの中にこのような何かを実装する必要がありますので、あなただけの、テキストフィールドを使用できるように表示されます。
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if([self presentationStyle] == MSMessagesAppPresentationStyleCompact) {
[self requestPresentationStyle:MSMessagesAppPresentationStyleExpanded];
self.didRequestKeyboard = YES;
return NO;
}
return YES;
}
-(void)didTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle {
// Called after the extension transitions to a new presentation style.
// Use this method to finalize any behaviors associated with the change in presentation style.
if(presentationStyle == MSMessagesAppPresentationStyleExpanded){
if(self.didRequestKeyboard){
[self.textField becomeFirstResponder];
self.didRequestKeyboard = NO;
}
}
}
私はこの問題に苦しんだ(iOSの10.2のように、まだ存在している)と、
fileprivate class TextField: UITextField {
override var canBecomeFirstResponder: Bool {
if let viewController = viewController as? MSMessagesAppViewController,
viewController.presentationStyle == .compact {
viewController.requestPresentationStyle(.expanded)
return false
}
return super.canBecomeFirstResponder
}
}
私はこれがAppleが解決しなければならない問題であると感じているので、「回避策」と言います。この解決策は一時的でなければなりません。この実装は、元の回答に代わるものとして、分離されており、容易に切り取ることができます。
同じ溶液を使用する以外はブロック
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if presentationStyle != .expanded {
didTransitionHandler = {
textField.becomeFirstResponder()
self.didTransitionHandler = nil
}
requestPresentationStyle(.expanded)
return false
}
return true
}
私はラインself.didRequestKeyboardでエラーを取得しています= YES; MSMessagesAppViewControllerクラスにUITextFieldDelegateを追加しました。 – Vin
@Vinこの変数は自分のクラスに実装されています – user339946
チャームのように働いていました。ありがとう! –