Commits

p2  committed ec93b47

Added animation when exiting thumb scrolling

  • Participants
  • Parent commits 8b0a02b

Comments (0)

Files changed (6)

File ThumbScrolling/PPTSRowView.h

 - (void)showText:(NSString *)aString withFont:(UIFont *)aFont at:(CGRect)aRect;
 
 - (void)foldWithFocusAt:(CGFloat)focusY inBubble:(CGFloat)bubbleSize withDensity:(CGFloat)density slowAnim:(BOOL)slow;
-- (void)foldUp:(void (^)(BOOL finished))completion;
+- (void)foldUpTowards:(CGRect)endFrame completion:(void (^)(BOOL finished))completion;
 
 - (CGFloat)yForFocusY:(CGFloat)focusY inBubble:(CGFloat)bubbleSize withDensity:(CGFloat)density;
 - (CATransform3D)transformForFocusY:(CGFloat)focusY inBubble:(CGFloat)bubbleSize withDensity:(CGFloat)density;

File ThumbScrolling/PPTSRowView.m

 }
 
 
-- (void)foldUp:(void (^)(BOOL finished))completion
+- (void)foldUpTowards:(CGRect)endFrame completion:(void (^)(BOOL finished))completion
 {
 	[UIView animateWithDuration:0.2
 					 animations:^{
+						 self.frame = endFrame;
 						 self.layer.transform = CATransform3DIdentity;
 					 }
 					 completion:completion];

File ThumbScrolling/PPTSView.h

 
 - (BOOL)startWithVisibleCells:(NSArray *)cellArray activeCell:(UITableViewCell *)activeCell activeIndex:(NSIndexPath *)activeIndexPath at:(CGFloat)startY asFraction:(CGFloat)fraction of:(NSUInteger)totalNum;
 - (void)moveTo:(CGPoint)hitPoint withMapping:(NSDictionary *)mapping order:(NSArray *)order active:(NSIndexPath *)activeIndexPath isBeginning:(BOOL)beginning;
-- (NSIndexPath *)endAnimated:(BOOL)animated;
+- (NSIndexPath *)endInTableView:(UITableView *)aTableView animated:(BOOL)animated;
 
 - (CGPoint)centerOfActiveRow;
 - (NSIndexPath *)indexPathOfActiveRow;

File ThumbScrolling/PPTSView.m

 	
 	// add top fake rows
 	CGRect fakeFrame = [self bounds];
-	fakeFrame.origin.y = 2.f;
-	fakeFrame.size.height = startY - bubbleSize/3*2 - 6.f;
+	fakeFrame.origin.y = -fakeFrame.size.height;
 	topFakeRows.frame = fakeFrame;
 	[self addSubview:topFakeRows];
 	
 	
 	// add bottom fake rows
 	fakeFrame = [self bounds];
-	fakeFrame.origin.y = startY + bubbleSize/2 - 6.f;		// 6: manual correction
-	fakeFrame.size.height = fakeFrame.size.height - 2.f - fakeFrame.origin.y;
+	fakeFrame.origin.y = fakeFrame.size.height;
+	fakeFrame.size.height = 3.f;					// don't go to zero to prevent issues (3px is the height of the bottom pattern image)
 	bottomFakeRows.frame = fakeFrame;
 	[self addSubview:bottomFakeRows];
 	
 	}
 	
 	// update fake rows
-	CGRect fakeFrame = topFakeRows.frame;
-	fakeFrame.origin.y = 2.f;
-	fakeFrame.size.height = hitPoint.y - bubbleSize/3*2 - 6.f;
-	topFakeRows.frame = fakeFrame;
+	CGRect topFrame = topFakeRows.frame;
+	topFrame.origin.y = 2.f;
+	topFrame.size.height = hitPoint.y - bubbleSize/3*2 - 6.f;		// 6: manual correction
 	
-	fakeFrame = [self bounds];
-	fakeFrame.origin.y = hitPoint.y + bubbleSize/2 - 6.f;			// 6: manual correction
-	fakeFrame.size.height = fakeFrame.size.height - 2.f - fakeFrame.origin.y;
-	bottomFakeRows.frame = fakeFrame;
+	CGRect botFrame = [self bounds];
+	botFrame.origin.y = hitPoint.y + bubbleSize/2 - 6.f;			// 6: manual correction
+	botFrame.size.height = botFrame.size.height - botFrame.origin.y - 2.f;
+	
+	if (beginning) {		// using 0.0 here if NOT beginning leaves artifacts compared to not assigning the frames in the animation block
+		[UIView animateWithDuration:0.3
+						 animations:^{
+							 topFakeRows.frame = topFrame;
+							 bottomFakeRows.frame = botFrame;
+						 }];
+	}
+	else {
+		topFakeRows.frame = topFrame;
+		bottomFakeRows.frame = botFrame;
+	}
 }
 
 
 /**
  *	Makes all rows fold up and returns the index path of the currently active row
  */
-- (NSIndexPath *)endAnimated:(BOOL)animated
+- (NSIndexPath *)endInTableView:(UITableView *)aTableView animated:(BOOL)animated
 {
 	id callback = ^(BOOL finished) {
 		self.rowQueue = nil;
-		[self removeFromSuperview];
+		[self removeFromSuperview];			/// @todo find a better solution, we must not remove ourselves from superview before the following loop is through
 	};
 	
 	// have all rows fold up
 	NSIndexPath *index = nil;
 	for (PPTSRowView *row in [self subviews]) {
 		if ([row isKindOfClass:[PPTSRowView class]]) {
-			[row foldUp:callback];
+			CGRect target = [self convertRect:[aTableView rectForRowAtIndexPath:row.indexPath] fromView:aTableView];
+			[row foldUpTowards:target completion:callback];
 			callback = nil;
 			
 			if (row.isActive) {
 	}
 	
 	// slide fake rows off
-	[topFakeRows removeFromSuperview];
-	[bottomFakeRows removeFromSuperview];
+	CGRect topFrame = topFakeRows.frame;
+	topFrame.origin.y = -topFrame.size.height;
+	CGRect botFrame = bottomFakeRows.frame;
+	botFrame.origin.y = [self bounds].size.height;
+	botFrame.size.height = 0.f;
+	
+	[UIView animateWithDuration:(animated ? 0.2 : 0.0)
+					 animations:^{
+						 topFakeRows.frame = topFrame;
+						 bottomFakeRows.frame = botFrame;
+					 }
+					 completion:^(BOOL finished){
+						 [topFakeRows removeFromSuperview];
+						 [bottomFakeRows removeFromSuperview];
+					 }];
 	
 	return index;
 }

File ThumbScrolling/PPThumbScrollingTableViewController.m

 		[parent moveTo:hitPoint withMapping:currentCells order:currentOrder active:nil isBeginning:YES];
 	}
 	else {
+		DLog(@"Something failed");
 		[parent removeFromSuperview];
 		self.parent = nil;
 	}
 - (void)moveThumbScrolling
 {
 	if (!longPress) {
-		DLog(@"Can't move, no long press recognizer in place!");
+		DLog(@"Can't move, there is no long press recognizer in place!");
 		return;
 	}
 	
 	[self.tableView scrollRectToVisible:rowRect animated:NO];
 	
 	// animate back into position
-	/// @todo implement
-	DLog(@"Visible cells: %@", [self.tableView visibleCells]);
-	[parent endAnimated:YES];
+	[parent endInTableView:self.tableView animated:YES];
 	
 	// clean up
 	self.parent = nil;

File ThumbScrolling/background_bottom.png

Old
Old image
New
New image