diff --git a/Example/PSPDFTextViewExample/PSTSampleViewController.m b/Example/PSPDFTextViewExample/PSTSampleViewController.m index 7f5b932..036a8fe 100644 --- a/Example/PSPDFTextViewExample/PSTSampleViewController.m +++ b/Example/PSPDFTextViewExample/PSTSampleViewController.m @@ -10,7 +10,7 @@ #import "PSPDFTextView.h" #include -@interface PSTSampleViewController () { +@interface PSTSampleViewController () { CGRect _keyboardRect; BOOL _keyboardVisible; } @@ -39,6 +39,7 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil]; PSPDFTextView *textView = [[PSPDFTextView alloc] initWithFrame:self.view.bounds]; + textView.delegate = self; textView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; textView.font = [UIFont systemFontOfSize:20.f]; textView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; @@ -92,4 +93,15 @@ - (void)dismissKeyboard { [self.view endEditing:YES]; } + +- (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView { + NSLog(@"Called %@", NSStringFromSelector(_cmd)); + return YES; +} + +- (BOOL)textViewShouldEndEditing:(UITextView *)aTextView { + NSLog(@"Called %@", NSStringFromSelector(_cmd)); + return YES; +} + @end diff --git a/PSPDFTextView.podspec b/PSPDFTextView.podspec index 1384009..9b75a4d 100644 --- a/PSPDFTextView.podspec +++ b/PSPDFTextView.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Peter Steinberger, PSPDFKit GmbH" => "steipete@gmail.com" } s.ios.deployment_target = '6.0' - s.source = { :git => "https://github.com/steipete/PSPDFTextView.git", :tag => "1.0.0" } + s.source = { :git => "https://github.com/steipete/PSPDFTextView.git", :tag => "#{s.version}" } s.source_files = 'PSPDFTextView/*.{h,m,c}' s.requires_arc = true; -end \ No newline at end of file +end diff --git a/PSPDFTextView/PSPDFTextView.m b/PSPDFTextView/PSPDFTextView.m index bfb4d0d..ffe8e50 100644 --- a/PSPDFTextView/PSPDFTextView.m +++ b/PSPDFTextView/PSPDFTextView.m @@ -11,7 +11,7 @@ #define kCFCoreFoundationVersionNumber_iOS_7_0 847.2 #endif -// Set this to YES of you only support iOS 7. +// Set this to YES if you only support iOS 7. #define PSPDFRequiresTextViewWorkarounds() (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) @interface PSPDFTextView () @@ -41,8 +41,12 @@ - (void)dealloc { - (void)setDelegate:(id)delegate { if (PSPDFRequiresTextViewWorkarounds()) { - [super setDelegate:delegate ? self : nil]; + // UIScrollView delegate keeps some flags that mark whether the delegate implements some methods (like scrollViewDidScroll:) + // setting *the same* delegate doesn't recheck the flags, so it's better to simply nil the previous delegate out + // we have to setup the realDelegate at first, since the flag check happens in setter + [super setDelegate:nil]; self.realDelegate = delegate != self ? delegate : nil; + [super setDelegate:delegate ? self : nil]; }else { [super setDelegate:delegate]; } @@ -128,7 +132,7 @@ - (void)ensureCaretIsVisibleWithReplacementText:(NSString *)text { }else { // Whenever the user enters text, see if we need to scroll to keep the caret on screen. // If it's not a newline, we don't need to add a delay to scroll. - // We don't aniamte since this sometimes ends up on the wrong position then. + // We don't animate since this sometimes ends up on the wrong position then. [self scrollToVisibleCaret]; } } @@ -195,13 +199,9 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)s { return [super methodSignatureForSelector:s] ?: [(id)self.realDelegate methodSignatureForSelector:s]; } -- (void)forwardInvocation:(NSInvocation *)invocation { +- (id)forwardingTargetForSelector:(SEL)s { id delegate = self.realDelegate; - if ([delegate respondsToSelector:invocation.selector]) { - [invocation invokeWithTarget:delegate]; - }else { - [super forwardInvocation:invocation]; - } + return [delegate respondsToSelector:s] ? delegate : [super forwardingTargetForSelector:s]; } @end