https://feedbackassistant.apple.com/feedback/12360292
Post
Replies
Boosts
Views
Activity
Code to reproduce:
#import "ViewController.h"
@interface ViewController () <UITextViewDelegate>
@property (nonatomic, strong) UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self registerForNotifications];
{
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
textView.backgroundColor = UIColor.whiteColor;
textView.delegate = self;
[self.view addSubview:textView];
self.textView = textView;
}
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"resign" forState:UIControlStateNormal];
[button sizeToFit];
button.center = CGPointMake(50, 250);
[button addTarget:self action:@selector(resign) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"switch" forState:UIControlStateNormal];
[button sizeToFit];
button.center = CGPointMake(150, 250);
[button addTarget:self action:@selector(switchV) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
{
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 300, 200, 100)];
textView.backgroundColor = UIColor.systemPinkColor;
[self.view addSubview:textView];
}
}
- (void)resign
{
[self.textView resignFirstResponder];
}
- (void)switchV
{
if (self.textView.inputView) {
self.textView.inputView = nil;
[self.textView reloadInputViews];
} else {
UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 200)];
inputView.backgroundColor = UIColor.greenColor;
self.textView.inputView = inputView;
[self.textView reloadInputViews];
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSLog(@"%@, %@", NSStringFromSelector(_cmd), NSStringFromRange(range));
return YES;
}
- (void)registerForNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardDidShowNotification:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardWillShowNotification:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardWillChangeFrameNotification:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardDidChangeFrameNotification:)
name:UIKeyboardDidChangeFrameNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardWillHideNotification:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveKeyboardDidHideNotification:)
name:UIKeyboardDidHideNotification
object:nil];
}
- (void)didReceiveKeyboardWillShowNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardWillShowNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
- (void)didReceiveKeyboardDidShowNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardDidShowNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
- (void)didReceiveKeyboardWillChangeFrameNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardWillChangeFrameNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
- (void)didReceiveKeyboardDidChangeFrameNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardDidChangeFrameNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
- (void)didReceiveKeyboardWillHideNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardWillHideNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
- (void)didReceiveKeyboardDidHideNotification:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardEndFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
NSLog(@"didReceiveKeyboardDidHideNotification %@ %ld", NSStringFromCGRect(keyboardEndFrame), animationCurve);
}
@end
https://feedbackassistant.apple.com/feedback/12452639