Skip to content

Commit

Permalink
initial animation
Browse files Browse the repository at this point in the history
  • Loading branch information
brung committed Feb 25, 2015
1 parent edf9899 commit a76a19d
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 7 deletions.
3 changes: 3 additions & 0 deletions unnamed/DetailQuestionCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
#import <UIKit/UIKit.h>
#import "Question.h"
#import "User.h"
#import "ProfileImageView.h"

@interface DetailQuestionCell : UITableViewCell
@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;

- (void) initWithQuestion:(Question *)question user:(User *)user totalCount:(NSInteger)count;

@end
5 changes: 4 additions & 1 deletion unnamed/DetailQuestionCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ @interface DetailQuestionCell()
@property (nonatomic, strong) User *user;
@property (nonatomic, assign) NSInteger totalVoteCount;

@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
Expand Down Expand Up @@ -50,4 +49,8 @@ - (void) initWithQuestion:(Question *)question user:(User *)user totalCount:(NSI
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
}

- (CGRect)profileImageviewFrame {
return self.profileImageView.frame;
}

@end
16 changes: 16 additions & 0 deletions unnamed/HomeProfileAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// HomeProfileAnimation.h
// unnamed
//
// Created by Bruce Ng on 2/22/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "SurveyViewCell.h"

@interface HomeProfileAnimation : NSObject <UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning, UINavigationControllerDelegate>
@property (nonatomic, strong) SurveyViewCell *selectedCell;
@property (nonatomic, assign) BOOL isPresenting;
@end
103 changes: 103 additions & 0 deletions unnamed/HomeProfileAnimation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// HomeProfileAnimation.m
// unnamed
//
// Created by Bruce Ng on 2/22/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import "HomeProfileAnimation.h"
#import "ProfileViewController.h"

@implementation HomeProfileAnimation
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 1;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView *containerView = [transitionContext containerView];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
CGPoint originalCenter = fromViewController.view.center;
CGPoint downCenter = CGPointMake(fromViewController.view.center.x, fromViewController.view.center.y + fromViewController.view.frame.size.height);
CGPoint rightCenter =CGPointMake(originalCenter.x + toViewController.view.frame.size.width, originalCenter.y);

if (self.isPresenting) {
NSLog(@"I'm presenting");

ProfileViewController *vc = (ProfileViewController *)toViewController;
toViewController.view.center = rightCenter;
[containerView addSubview:toViewController.view];
ProfileImageView *remoteProfileImageView = [vc getMainProfileImageView];
remoteProfileImageView.hidden = YES;

UIImageView *selectedProfileImage = self.selectedCell.profileImageView;

CGRect profileImageFrame = [self.selectedCell profileImageviewFrame];
UIImageView *transImageView = [[ProfileImageView alloc] initWithFrame:profileImageFrame];
transImageView.layer.cornerRadius = transImageView.frame.size.width / 2;
transImageView.image = selectedProfileImage.image;
transImageView.contentMode = UIViewContentModeScaleAspectFill;
transImageView.clipsToBounds = YES;
transImageView.center = selectedProfileImage.center;
transImageView.transform = CGAffineTransformMakeScale(1.15,1.15);
[containerView insertSubview:transImageView aboveSubview:toViewController.view];

selectedProfileImage.hidden = YES;
[UIView animateWithDuration:1 animations:^{
CGFloat widthScale = (remoteProfileImageView.frame.size.width/selectedProfileImage.frame.size.width);
CGFloat heightScale = (remoteProfileImageView.frame.size.height/selectedProfileImage.frame.size.height);
transImageView.transform = CGAffineTransformScale(selectedProfileImage.transform, widthScale, heightScale);
transImageView.center = remoteProfileImageView.center;
toViewController.view.center = originalCenter;
fromViewController.view.alpha = 0.5;
// fromViewController.view.center = downCenter;
// fromViewController.view.transform = CGAffineTransformMakeScale(0.90, 0.90);
} completion:^(BOOL finished) {
[transImageView removeFromSuperview];
[transitionContext completeTransition:YES];
selectedProfileImage.hidden = NO;
remoteProfileImageView.hidden = NO;
}];
} else {
NSLog(@"I'm dismissing");
[containerView insertSubview:toViewController.view belowSubview:fromViewController.view];
// toViewController.view.center = downCenter;
[fromViewController dismissViewControllerAnimated:YES completion:nil];
[UIView animateWithDuration:1 animations:^{
fromViewController.view.center = rightCenter;
toViewController.view.alpha =1;
// toViewController.view.center = originalCenter;
// toViewController.view.transform = CGAffineTransformMakeScale(1.0,1.0);
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
[fromViewController.view removeFromSuperview];
}];
}
}


#pragma mark - transitionDelegate
- (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
self.isPresenting = YES;
return self;
}

- (id )animationControllerForDismissedController:(UIViewController *)dismissed {
self.isPresenting = NO;
return self;
}


- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
if (operation == UINavigationControllerOperationPush) {
self.isPresenting = YES;
} else if (operation == UINavigationControllerOperationPop) {
self.isPresenting = NO;
}
return self;
}

@end
9 changes: 8 additions & 1 deletion unnamed/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "SurveyViewCell.h"
#import "ParseClient.h"
#import "UIColor+AppColor.h"
#import "HomeProfileAnimation.h"

NSString * const kSurveyViewCell = @"SurveyViewCell";

Expand All @@ -23,6 +24,7 @@ @interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, Su
@property (nonatomic, assign) BOOL isUpdating;
@property (nonatomic, assign) BOOL isInsertingNewPost;
@property (nonatomic, strong) SurveyViewCell * prototypeSurveyCell;
@property (nonatomic, strong) HomeProfileAnimation *transitionAnimation;

@end

Expand Down Expand Up @@ -65,6 +67,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor appBgColor];
self.transitionAnimation = [[HomeProfileAnimation alloc] init];
self.navigationController.delegate = self.transitionAnimation;
self.navigationController.modalPresentationStyle = UIModalPresentationCustom;

//Setup Notification listener
self.isInsertingNewPost = NO;
Expand Down Expand Up @@ -190,6 +195,8 @@ - (void)surveyViewCell:(SurveyViewCell *)cell didClickOnUser:(User *)user {
} else {
ProfileViewController *vc = [[ProfileViewController alloc] init];
vc.user = user;
vc.view.frame = self.view.frame;
self.transitionAnimation.selectedCell = cell;
[self.navigationController pushViewController:vc animated:YES];
}
}
Expand All @@ -216,4 +223,4 @@ - (void)configureCell:(UITableViewCell *)pCell forRowAtIndexPath:(NSIndexPath *)
}
}

@end
@end
2 changes: 2 additions & 0 deletions unnamed/ProfileCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#import <UIKit/UIKit.h>
#import "User.h"
#import "ProfileImageView.h"

@interface ProfileCell : UITableViewCell
@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;
@property (nonatomic, strong) User * user;
@end
1 change: 0 additions & 1 deletion unnamed/ProfileCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@interface ProfileCell()

//############################################################
@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UILabel *profileTitleLabel;

//############################################################
Expand Down
2 changes: 1 addition & 1 deletion unnamed/ProfileImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ - (IBAction)onImageTap:(UITapGestureRecognizer *)sender {
[UIView animateWithDuration:0.2 animations:^{
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
} completion:^(BOOL finished) {
[self.delegate profileImageView:self tappedUser:self.user];
[UIView animateWithDuration:0.2 animations:^{
self.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
[self.delegate profileImageView:self tappedUser:self.user];
}];
}];
}
Expand Down
2 changes: 2 additions & 0 deletions unnamed/ProfileViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#import <UIKit/UIKit.h>
#import "User.h"
#import "ProfileImageView.h"

@interface ProfileViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) User *user;

- (ProfileImageView *)getMainProfileImageView;
@end
5 changes: 5 additions & 0 deletions unnamed/ProfileViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - Animation
- (ProfileImageView *)getMainProfileImageView {
ProfileCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
return cell.profileImageView;
}

#pragma mark - Private methods
- (void) onRefresh{
Expand Down
4 changes: 4 additions & 0 deletions unnamed/SurveyViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
#import <UIKit/UIKit.h>
#import "Survey.h"
#import "User.h"
#import "ProfileImageView.h"

@class SurveyViewCell;
@protocol SurveyViewCellDelegate <NSObject>
-(void)surveyViewCell:(SurveyViewCell *)cell didClickOnUser:(User *)user;
@end

@interface SurveyViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;
@property (nonatomic, strong) Survey *survey;
@property (nonatomic, strong) id<SurveyViewCellDelegate> delegate;
- (CGRect)profileImageviewFrame;

@end
8 changes: 6 additions & 2 deletions unnamed/SurveyViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
//

#import "SurveyViewCell.h"
#import "ProfileImageView.h"
#import "AnswerCollectionView.h"
#import "CommentCollectionView.h"
#import "UIColor+AppColor.h"
#import "NSDate+MinimalTimeAgo.h"

@interface SurveyViewCell () <ProfileImageViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet ProfileImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UILabel *createdByLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
Expand Down Expand Up @@ -60,4 +58,10 @@ - (void)setSurvey:(Survey *)survey {
- (void)profileImageView:(ProfileImageView *)view tappedUser:(User *)user {
[self.delegate surveyViewCell:self didClickOnUser:user];
}

- (CGRect)profileImageviewFrame {
float originX = self.contentView.frame.origin.x + self.containerView.frame.origin.x + self.profileImageView.frame.origin.x;
float originY = self.contentView.frame.origin.y + self.containerView.frame.origin.y + self.profileImageView.frame.origin.y;
return CGRectMake(originX, originY, self.profileImageView.frame.size.width, self.profileImageView.frame.size.height);
}
@end
2 changes: 1 addition & 1 deletion unnamed/SurveyViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
Expand Down
1 change: 1 addition & 0 deletions unnamed/SurveyViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

@interface SurveyViewController : UIViewController
@property (nonatomic, strong) Survey *survey;
- (UIImageView *)getMainProfileImageView;
@end
6 changes: 6 additions & 0 deletions unnamed/SurveyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}

- (UIImageView *)getMainProfileImageView {
DetailQuestionCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
return cell.profileImageView;
}


@end

0 comments on commit a76a19d

Please sign in to comment.