Skip to content

Commit

Permalink
Merge pull request #1 from steipete/master
Browse files Browse the repository at this point in the history
Update from steipete:master
  • Loading branch information
hpique committed Feb 4, 2014
2 parents d5eaa24 + ff6db53 commit 3bdadb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
14 changes: 13 additions & 1 deletion Example/PSPDFTextViewExample/PSTSampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "PSPDFTextView.h"
#include <tgmath.h>

@interface PSTSampleViewController () {
@interface PSTSampleViewController () <UITextViewDelegate> {
CGRect _keyboardRect;
BOOL _keyboardVisible;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions PSPDFTextView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
18 changes: 9 additions & 9 deletions PSPDFTextView/PSPDFTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 () <UITextViewDelegate>
Expand Down Expand Up @@ -41,8 +41,12 @@ - (void)dealloc {

- (void)setDelegate:(id<UITextViewDelegate>)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];
}
Expand Down Expand Up @@ -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];
}
}
Expand Down Expand Up @@ -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

0 comments on commit 3bdadb1

Please sign in to comment.