画面全体に半透明の黒いマスクを配置する方法を誰かに教えてもらえますか?ただし、特定の UIView の領域は除外されますか? テキストフィールドの外側の部分がタップされると、resignFirstResponder を呼び出す UITextField に対してこのマスクを使用したいと考えています。
サブビュー ツリーは次のようになります。
UIWindow
|-UIView
| |-UITextField
|
|-マスク
ありがとう、
次のものを使用できます。
- (void)bringSubviewToFront:(UIView *)view
そして、ブラック マスク ビューを追加した後、UITextField を前面に送信します。
アップデート
これを行う手順は次のとおりです (詳細については、UIGestureRecognizers のアップルの例を参照してください)。
GestureRecognizer を作成し、それを maskView に追加します。
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
recognizer.delegate = self;
UIImageView *maskView = [[UIImageView alloc] init];
[maskView addGestureRecognizer:recognizer];
ビューコントローラーを「UIGestureRecognizerDelegate」のデリゲートとして設定する必要があります
@interface YourViewController : UIViewController <UIGestureRecognizerDelegate>
画面をマスクする場合は、ViewController に maskView を追加します。次に、テキスト フィールドをマスクの上に移動します。
[self.view addSubView:maskView]; [self.view BringSubviewToFront:textField];
この2つの機能を設定します。最初の機能では、ユーザーがマスクに触れた場合のアクションを設定できます
- (void)handleTapFrom:(UITapGestureRecognizer *)recognizer {
//resign the first responder when the user taps the mask
//you can remove the mask here if you want to
2 つ目では、textField からのタッチを受信しないようにアプリに指示します
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// Disallow recognition of tap gestures in the segmented control.
if ((touch.view == textField)) {//checks if the touch is on the textField
return NO;
}
return YES;
}
それが意味をなすことを願っています
シャニ