Skip to content

Commit

Permalink
Several Fixes, cleaned up code & new transitioning effect
Browse files Browse the repository at this point in the history
  • Loading branch information
mmackh committed Jul 2, 2013
1 parent 1424d2f commit 7a41f6b
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 64 deletions.
14 changes: 14 additions & 0 deletions Hacker News.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
22CB50BD176F5416006DA4AC /* MAMCommentTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 22CB50BC176F5416006DA4AC /* MAMCommentTableViewCell.m */; };
22CB50D4176FA375006DA4AC /* TTTAttributedLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 22CB50D3176FA375006DA4AC /* TTTAttributedLabel.m */; };
22CB50D6176FA4CC006DA4AC /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22CB50D5176FA4CC006DA4AC /* CoreText.framework */; };
22E8DD5C1782E7F800137E75 /* UIView+AnchorPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E8DD5B1782E7F800137E75 /* UIView+AnchorPoint.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -273,6 +274,8 @@
22CB50D2176FA375006DA4AC /* TTTAttributedLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTTAttributedLabel.h; sourceTree = "<group>"; };
22CB50D3176FA375006DA4AC /* TTTAttributedLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTTAttributedLabel.m; sourceTree = "<group>"; };
22CB50D5176FA4CC006DA4AC /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
22E8DD5A1782E7F800137E75 /* UIView+AnchorPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AnchorPoint.h"; sourceTree = "<group>"; };
22E8DD5B1782E7F800137E75 /* UIView+AnchorPoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AnchorPoint.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -419,6 +422,7 @@
223191D7176C5E570006084D /* Dependencies */ = {
isa = PBXGroup;
children = (
22E8DD591782E7D800137E75 /* Helpers */,
229C34E81782017900CC56E1 /* UIActivity */,
226339AD177B85BE00B2270A /* MAMSlideNavigationViewController */,
22CB50BE176F8EE7006DA4AC /* TTAttributedLabel */,
Expand Down Expand Up @@ -646,6 +650,15 @@
name = Webview;
sourceTree = "<group>";
};
22E8DD591782E7D800137E75 /* Helpers */ = {
isa = PBXGroup;
children = (
22E8DD5A1782E7F800137E75 /* UIView+AnchorPoint.h */,
22E8DD5B1782E7F800137E75 /* UIView+AnchorPoint.m */,
);
name = Helpers;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -809,6 +822,7 @@
223246D0178008F700707BCD /* PocketAPIOperation.m in Sources */,
223246D1178008F700707BCD /* SFHFKeychainUtils.m in Sources */,
229C34E71782016D00CC56E1 /* ReadabilityActivity.m in Sources */,
22E8DD5C1782E7F800137E75 /* UIView+AnchorPoint.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
18 changes: 10 additions & 8 deletions Hacker News/MAMHNStory.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@
#import "RXMLElement.h"

@implementation MAMHNStory
{
NSString *_subtitle;
NSString *_footer;
}

- (NSString *)subtitle
{
static NSString *subtitle = nil;
if (!subtitle)
if (!_subtitle)
{
subtitle = [NSString stringWithFormat:@"Submitted %@ by %@",self.pubDate,self.user];
_subtitle = [NSString stringWithFormat:@"Submitted %@ by %@",self.pubDate,self.user];
}
return subtitle;
return _subtitle;
}

- (NSString *)footer
{
static NSString *footer = nil;
if (!footer)
if (!_footer)
{
footer = [NSString stringWithFormat:@"%@ | %@",self.score,self.commentsValue];
_footer = [NSString stringWithFormat:@"%@ | %@",self.score,self.commentsValue];
}
return footer;
return _footer;
}

- (NSString *)domain
Expand Down
31 changes: 4 additions & 27 deletions Hacker News/MAMReaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#import "NSString+Additions.h"
#import <QuartzCore/QuartzCore.h>

//Categories
#import "UIView+AnchorPoint.h"

// UIActivity
#import "TUSafariActivity.h"
#import "PocketAPIActivity.h"
Expand Down Expand Up @@ -296,7 +299,7 @@ - (void)transitionToStory:(StoryTransitionType)transitionType
[stretchAnimation setBeginTime:CACurrentMediaTime() + 0.35];
}
[stretchAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self setAnchorPoint:CGPointMake(0.0, (transitionType==StoryTransitionTypeNext)?1:0) forView:self.view];
[self.view setAnchorPoint:CGPointMake(0.0, (transitionType==StoryTransitionTypeNext)?1:0) forView:self.view];
[self.view.layer addAnimation:stretchAnimation forKey:@"stretchAnimation"];
if (story == nil) return;
CATransition *animation = [CATransition animation];
Expand All @@ -309,30 +312,4 @@ - (void)transitionToStory:(StoryTransitionType)transitionType
[self setStory:story];
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self setAnchorPoint:CGPointMake(0.5, 0.5) forView:self.webView];
}

//http://stackoverflow.com/a/5666430/1091044
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y);

newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

CGPoint position = view.layer.position;

position.x -= oldPoint.x;
position.x += newPoint.x;

position.y -= oldPoint.y;
position.y += newPoint.y;

view.layer.position = position;
view.layer.anchorPoint = anchorPoint;
}

@end
13 changes: 13 additions & 0 deletions Hacker News/MAMSlideNavigationViewController.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#import "MAMSlideNavigationViewController.h"

//Categories
#import "UIView+AnchorPoint.h"

@interface MAMSlideNavigationViewController ()

@end
Expand All @@ -15,6 +18,16 @@ - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)ani
{
if(animated)
{
CABasicAnimation *stretchAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
[stretchAnimation setToValue:[NSNumber numberWithFloat:1.04]];
[stretchAnimation setRemovedOnCompletion:YES];
[stretchAnimation setFillMode:kCAFillModeRemoved];
[stretchAnimation setAutoreverses:YES];
[stretchAnimation setDuration:0.15];
[stretchAnimation setBeginTime:CACurrentMediaTime() + 0.3];
[stretchAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view setAnchorPoint:CGPointMake(1, 0.5) forView:self.view];
[self.view.layer addAnimation:stretchAnimation forKey:@"stretchAnimation"];

CATransition *transition = [CATransition animation];
transition.duration = 0.4f;
Expand Down
33 changes: 4 additions & 29 deletions Hacker News/MAMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#import <QuartzCore/QuartzCore.h>
#import "MAMButton.h"

//Categories
#import "UIView+AnchorPoint.h"

@interface MAMViewController () <UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate,ReaderViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
Expand Down Expand Up @@ -172,7 +175,7 @@ - (IBAction)changeSection:(id)sender
if (_currentSection == 0 && [sender tag] == 0) {
anchorPointX = 0;
}
[self setAnchorPoint:CGPointMake(anchorPointX,0.5) forView:self.view];
[self.view setAnchorPoint:CGPointMake(anchorPointX,0.5) forView:self.view];
[self.view.layer addAnimation:stretchAnimation forKey:@"animations"];

if (_currentSection != [sender tag])
Expand Down Expand Up @@ -264,32 +267,4 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
return NO;
}

// Clean up, duplicate code

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self setAnchorPoint:CGPointMake(0.5, 0.5) forView:self.tableView];
}

//http://stackoverflow.com/a/5666430/1091044
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y);

newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

CGPoint position = view.layer.position;

position.x -= oldPoint.x;
position.x += newPoint.x;

position.y -= oldPoint.y;
position.y += newPoint.y;

view.layer.position = position;
view.layer.anchorPoint = anchorPoint;
}

@end
15 changes: 15 additions & 0 deletions Hacker News/UIView+AnchorPoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UIView.h
// Hacker News
//
// Created by Maximilian Mackh on 02/07/13.
// Copyright (c) 2013 Maximilian Mackh. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIView (AnchorPoint)

-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view;

@end
36 changes: 36 additions & 0 deletions Hacker News/UIView+AnchorPoint.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// UIView.m
// Hacker News
//
// Created by Maximilian Mackh on 02/07/13.
// Copyright (c) 2013 Maximilian Mackh. All rights reserved.
//

#import "UIView+AnchorPoint.h"
#import <QuartzCore/QuartzCore.h>

@implementation UIView (AnchorPoint)

//Thanks http://stackoverflow.com/a/5666430/1091044

-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y);

newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

CGPoint position = view.layer.position;

position.x -= oldPoint.x;
position.x += newPoint.x;

position.y -= oldPoint.y;
position.y += newPoint.y;

view.layer.position = position;
view.layer.anchorPoint = anchorPoint;
}

@end

0 comments on commit 7a41f6b

Please sign in to comment.