@@ -64,6 +64,7 @@ - (void)commonInit
64
64
[self setupViewConstraints ];
65
65
66
66
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (didChangeTextView: ) name: UITextViewTextDidChangeNotification object: nil ];
67
+ [self .leftButton.imageView addObserver: self forKeyPath: NSStringFromSelector (@selector (image )) options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: NULL ];
67
68
}
68
69
69
70
@@ -460,7 +461,7 @@ - (void)updateConstraintConstants
460
461
{
461
462
self.accessoryViewHC .constant = zero;
462
463
463
- CGSize leftButtonSize = [self .leftButton imageForState: UIControlStateNormal ].size ;
464
+ CGSize leftButtonSize = [self .leftButton imageForState: self .leftButton.state ].size ;
464
465
465
466
self.leftButtonWC .constant = roundf (leftButtonSize.width );
466
467
self.leftButtonHC .constant = roundf (leftButtonSize.height );
@@ -472,12 +473,30 @@ - (void)updateConstraintConstants
472
473
}
473
474
}
474
475
476
+ #pragma mark - Observers
477
+
478
+ - (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context
479
+ {
480
+ if ([object isEqual: self .leftButton.imageView] && [keyPath isEqualToString: NSStringFromSelector (@selector (image ))]) {
481
+ UIImage *newImage = change[NSKeyValueChangeNewKey ];
482
+ UIImage *oldImage = change[NSKeyValueChangeOldKey ];
483
+ if ([newImage isEqual: oldImage]) {
484
+ return ;
485
+ }
486
+ [self updateConstraintConstants ];
487
+ }
488
+ else {
489
+ [super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
490
+ }
491
+ }
492
+
475
493
476
494
#pragma mark - Lifeterm
477
495
478
496
- (void )dealloc
479
497
{
480
498
[[NSNotificationCenter defaultCenter ] removeObserver: self name: UITextViewTextDidChangeNotification object: nil ];
499
+ [self removeObserver: self .leftButton.imageView forKeyPath: NSStringFromSelector (@selector (image ))];
481
500
482
501
_leftButton = nil ;
483
502
_rightButton = nil ;
0 commit comments