Skip to content

Commit

Permalink
Voice now screenshots the current page before pushing, to allow for a…
Browse files Browse the repository at this point in the history
… smoother transition. Also remembers the scroll position of each page and resets it when it comes back.
  • Loading branch information
shnhrrsn committed Jan 27, 2010
1 parent 3cab103 commit f545ea7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Classes/Controllers/WebViewController/WebViewController.h
Expand Up @@ -12,11 +12,14 @@
@interface WebViewController : UIViewController<UIWebViewDelegate> {
@private
BOOL allowScrolling;
UIImageView* placeHolderImageView;
CGPoint scrollPosition;
}

- (void)loadURL:(NSURL*)URL;

@property(nonatomic,readonly) UIWebView* webView;
@property(nonatomic,assign) BOOL allowScrolling;
@property(nonatomic,readonly) NSURL* defaultURL;
@property(nonatomic,assign) CGPoint scrollPosition;
@end
43 changes: 37 additions & 6 deletions Classes/Controllers/WebViewController/WebViewController.m
Expand Up @@ -7,6 +7,7 @@
//

#import "WebViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface UIView (UIScroller)
@property(nonatomic,assign) BOOL scrollingEnabled;
Expand All @@ -17,11 +18,12 @@ @interface UIView (UIScroller)
static UIWebView* __webView;

@implementation WebViewController
@synthesize allowScrolling;
@synthesize allowScrolling, scrollPosition;

- (id)init {
if((self = [super init])) {
self.allowScrolling = YES;
self.scrollPosition = CGPointZero;
}

return self;
Expand All @@ -31,15 +33,23 @@ - (id)init {
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];

if(!placeHolderImageView) {
placeHolderImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
placeHolderImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

[self.view insertSubview:placeHolderImageView atIndex:0];
}

- (void)awakeFromNib {
[super awakeFromNib];
self.allowScrolling = YES;
self.scrollPosition = CGPointZero;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

@synchronized(self) {
if(!__webView) {
Expand All @@ -58,8 +68,29 @@ - (void)viewDidAppear:(BOOL)animated {
__webView.frame = self.view.bounds;
__webView.delegate = self;
((UIView*)[[__webView subviews] lastObject]).scrollingEnabled = self.allowScrolling;
((UIView*)[[__webView subviews] lastObject]).offset = CGPointZero;
[self loadURL:self.defaultURL];

if(placeHolderImageView.image) {
[self.view bringSubviewToFront:placeHolderImageView];
}
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.view bringSubviewToFront:self.webView];
((UIView*)[[__webView subviews] lastObject]).offset = self.scrollPosition;
}

- (void)viewWillDisappear:(BOOL)animated {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
placeHolderImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.scrollPosition = ((UIView*)[[__webView subviews] lastObject]).offset;

[self.view bringSubviewToFront:placeHolderImageView];
[super viewWillDisappear:animated];
}

- (void)loadURL:(NSURL*)URL {
Expand Down Expand Up @@ -116,12 +147,12 @@ - (void)didReceiveMemoryWarning {
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
[placeHolderImageView release], placeHolderImageView = nil;
}


- (void)dealloc {
[placeHolderImageView release], placeHolderImageView = nil;
[super dealloc];
}

Expand Down
4 changes: 4 additions & 0 deletions Voice.xcodeproj/project.pbxproj
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
283BA7DB11107C5300228649 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 283BA7DA11107C5300228649 /* QuartzCore.framework */; };
288765080DF74369002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765070DF74369002DB57D /* CoreGraphics.framework */; };
28A32A6F110F853200C43971 /* VoiceAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 28A32A50110F853200C43971 /* VoiceAppDelegate.m */; };
28A32A70110F853200C43971 /* ComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28A32A53110F853200C43971 /* ComposeViewController.m */; };
Expand All @@ -31,6 +32,7 @@
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D6058910D05DD3D006BFB54 /* Voice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Voice.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
283BA7DA11107C5300228649 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
288765070DF74369002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28A32A4F110F853200C43971 /* VoiceAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VoiceAppDelegate.h; sourceTree = "<group>"; };
28A32A50110F853200C43971 /* VoiceAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VoiceAppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -69,6 +71,7 @@
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765080DF74369002DB57D /* CoreGraphics.framework in Frameworks */,
283BA7DB11107C5300228649 /* QuartzCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -258,6 +261,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
283BA7DA11107C5300228649 /* QuartzCore.framework */,
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765070DF74369002DB57D /* CoreGraphics.framework */,
Expand Down

0 comments on commit f545ea7

Please sign in to comment.