Skip to content

Commit

Permalink
#26 Headers and Footers
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jan 3, 2015
1 parent 4e71f39 commit d0fb898
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.telerik.plugins.nativepagetransitions"
version="0.2.7">
version="0.2.8">

<name>Native Page Transitions</name>

Expand Down
2 changes: 2 additions & 0 deletions src/ios/NativePageTransitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

@interface NativePageTransitions : CDVPlugin

@property (strong, nonatomic) IBOutlet UIImageView *screenShotImageViewTop;
@property (strong, nonatomic) IBOutlet UIImageView *screenShotImageViewBottom;
@property (strong, nonatomic) IBOutlet UIImageView *screenShotImageView;
@property (strong, nonatomic) IBOutlet CDVInvokedUrlCommand *command;

Expand Down
41 changes: 36 additions & 5 deletions src/ios/NativePageTransitions.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ - (void) slide:(CDVInvokedUrlCommand*)command {
NSTimeInterval delay = [[args objectForKey:@"iosdelay"] doubleValue];
NSString *href = [args objectForKey:@"href"];
NSNumber *slowdownfactor = [args objectForKey:@"slowdownfactor"];

NSNumber *fixedPixelsTopNum = [args objectForKey:@"fixedPixelsTop"];
NSNumber *fixedPixelsBottomNum = [args objectForKey:@"fixedPixelsBottom"];
int fixedPixelsTop = [fixedPixelsTopNum intValue];
int fixedPixelsBottom = [fixedPixelsBottomNum intValue];

self.viewController.view.backgroundColor = [UIColor blackColor];
self.webView.layer.shadowOpacity = 0;

Expand Down Expand Up @@ -79,17 +83,15 @@ - (void) slide:(CDVInvokedUrlCommand*)command {

_screenShotImageView = [[UIImageView alloc]initWithFrame:screenshotRect];
[_screenShotImageView setImage:image];
CGFloat retinaFactor = DISPLAY_SCALE;

// in case of a statusbar above the webview, crop off the top
// TODO this can also be used for not scrolling fixed headers and footers
if (_nonWebViewHeight > 0 && [direction isEqualToString:@"down"]) {
CGFloat retinaFactor = DISPLAY_SCALE;
CGRect rect = CGRectMake(0.0, _nonWebViewHeight*retinaFactor, image.size.width*retinaFactor, (image.size.height-_nonWebViewHeight)*retinaFactor);
CGRect rect2 = CGRectMake(0.0, _nonWebViewHeight, image.size.width, image.size.height-_nonWebViewHeight);
CGImageRef tempImage = CGImageCreateWithImageInRect([image CGImage], rect);
UIImage *newImage = [UIImage imageWithCGImage:tempImage];
_screenShotImageView = [[UIImageView alloc]initWithFrame:rect2];
[_screenShotImageView setImage:newImage];
[_screenShotImageView setImage:[UIImage imageWithCGImage:tempImage]];
CGImageRelease(tempImage);
}

Expand All @@ -98,6 +100,32 @@ - (void) slide:(CDVInvokedUrlCommand*)command {
} else {
[UIApplication.sharedApplication.keyWindow.subviews.lastObject insertSubview:_screenShotImageView aboveSubview:self.webView];
}

// Make a cropped version of the screenshot with only the top and/or bottom piece. Only for left/right slides atm.
if ([direction isEqualToString:@"left"] || [direction isEqualToString:@"right"]) {
if (fixedPixelsTop > 0) {
CGRect rect = CGRectMake(0.0, fixedPixelsTop*retinaFactor, image.size.width*retinaFactor, fixedPixelsTop*retinaFactor);
CGRect rect2 = CGRectMake(0.0, fixedPixelsTop, image.size.width, fixedPixelsTop);
CGImageRef tempImage = CGImageCreateWithImageInRect([image CGImage], rect);
_screenShotImageViewTop = [[UIImageView alloc]initWithFrame:rect2];
[_screenShotImageViewTop setImage:[UIImage imageWithCGImage:tempImage]];
CGImageRelease(tempImage);
[UIApplication.sharedApplication.keyWindow.subviews.lastObject
insertSubview:_screenShotImageViewTop
aboveSubview:([direction isEqualToString:@"left"] ? self.webView : self.screenShotImageView)];
}
if (fixedPixelsBottom > 0) {
CGRect rect = CGRectMake(0.0, (image.size.height-fixedPixelsBottom)*retinaFactor, image.size.width*retinaFactor, fixedPixelsBottom*retinaFactor);
CGRect rect2 = CGRectMake(0.0, image.size.height-fixedPixelsBottom, image.size.width, fixedPixelsBottom);
CGImageRef tempImage = CGImageCreateWithImageInRect([image CGImage], rect);
_screenShotImageViewBottom = [[UIImageView alloc]initWithFrame:rect2];
[_screenShotImageViewBottom setImage:[UIImage imageWithCGImage:tempImage]];
CGImageRelease(tempImage);
[UIApplication.sharedApplication.keyWindow.subviews.lastObject
insertSubview:_screenShotImageViewBottom
aboveSubview:([direction isEqualToString:@"left"] ? self.webView : self.screenShotImageView)];
}
}

if ([self loadHrefIfPassed:href]) {
[UIView animateWithDuration:duration
Expand Down Expand Up @@ -133,6 +161,9 @@ - (void) slide:(CDVInvokedUrlCommand*)command {
[self.webView setFrame:CGRectMake(0, webviewToY, width, height)];
}
completion:^(BOOL finished) {
// doesn't matter if these weren't added
[_screenShotImageViewTop removeFromSuperview];
[_screenShotImageViewBottom removeFromSuperview];
}];

if ([slowdownfactor intValue] != 1 && ([direction isEqualToString:@"right"] || [direction isEqualToString:@"down"])) {
Expand Down

0 comments on commit d0fb898

Please sign in to comment.