You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/07/15 04:56:57 UTC
[2/3] git commit: CB-6626 ios: Add a JS event for tapping on statusbar
CB-6626 ios: Add a JS event for tapping on statusbar
close #4
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/f0031ca2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/f0031ca2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/f0031ca2
Branch: refs/heads/master
Commit: f0031ca2b4d778d8feea1959ec1fd8773ad39872
Parents: 6552bdd
Author: Tiancheng Zhu <ph...@gmail.com>
Authored: Thu Apr 10 16:56:24 2014 -0700
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jul 14 22:56:21 2014 -0400
----------------------------------------------------------------------
src/ios/CDVStatusBar.m | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/f0031ca2/src/ios/CDVStatusBar.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m
index e773397..98f2285 100644
--- a/src/ios/CDVStatusBar.m
+++ b/src/ios/CDVStatusBar.m
@@ -70,6 +70,10 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
@end
+@interface CDVStatusBar () <
+ UIScrollViewDelegate>
+@end
+
@implementation CDVStatusBar
- (id)settingForKey:(NSString*)key
@@ -120,6 +124,16 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
if ([self settingForKey:setting]) {
[self setStatusBarStyle:[self settingForKey:setting]];
}
+
+ // blank scroll view to intercept status bar taps
+ self.webView.scrollView.scrollsToTop = NO;
+ UIScrollView *fakeScrollView = [[UIScrollView alloc] initWithFrame:UIScreen.mainScreen.bounds];
+ fakeScrollView.delegate = self;
+ fakeScrollView.scrollsToTop = YES;
+ [self.viewController.view addSubview:fakeScrollView]; // Add scrollview to the view heirarchy so that it will begin accepting status bar taps
+ [self.viewController.view sendSubviewToBack:fakeScrollView]; // Send it to the very back of the view heirarchy
+ fakeScrollView.contentSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height * 2.0f); // Make the scroll view longer than the screen itself
+ fakeScrollView.contentOffset = CGPointMake(0.0f, UIScreen.mainScreen.bounds.size.height); // Scroll down so a tap will take scroll view back to the top
}
- (void) _ready:(CDVInvokedUrlCommand*)command
@@ -411,4 +425,12 @@ static const void *kStatusBarStyle = &kStatusBarStyle;
}
+#pragma mark - UIScrollViewDelegate
+
+- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
+{
+ [self.webView stringByEvaluatingJavaScriptFromString:@"var evt = document.createEvent(\"Event\"); evt.initEvent(\"statusTap\",true,true); window.dispatchEvent(evt);"];
+ return NO;
+}
+
@end