Permalink
Browse files

Merge pull request #1 from Reefaq/master

fixed fast scroll animation effect
  • Loading branch information...
2 parents ccfcd23 + 9b11863 commit 16352249eda7e1ad1e5d5692e57e7f334ff0cb47 @Reefaq Reefaq committed Jun 18, 2012
Showing with 72 additions and 48 deletions.
  1. +72 −48 Scroller/ScrollView.m
View
@@ -55,8 +55,8 @@ - (void) load {
views = [[NSMutableArray alloc] init];
currentIndex = -1;
- coverSize = CGSizeMake(224, 200);
- spaceFromCurrent = coverSize.height/2.4;
+ coverSize = CGSizeMake(250, 50);
+ spaceFromCurrent = (coverSize.width/2) - 45;
[self setup];
}
@@ -73,51 +73,81 @@ - (void) setup {
- (void) animateToIndex:(int)index animated:(BOOL)animated {
- NSString *string = @"";
+// NSString *string = @"";
+ float speed = 0;
if(velocity> 200) animated = NO;
if(animated){
- float speed = 0.21;
+ speed = 0.20;
if(velocity>80)speed=0.05;
- [UIView beginAnimations:string context:nil];
+/* [UIView beginAnimations:string context:nil];
[UIView setAnimationDuration:speed];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
- [UIView setAnimationBeginsFromCurrentState:YES];
+ [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
+ [UIView setAnimationBeginsFromCurrentState:NO]; */
}
-
+
int currentViewIndex = 0;
for(UIView *v in views){
- v.alpha = 1;
+ //v.alpha = 0;
if (currentViewIndex == index) {
- [v setBackgroundColor:RGBACOLOR(255,255,255,1)];
- v.layer.transform = CATransform3DMakeTranslation(-(spaceFromCurrent-30), 0, -300);
+ v.alpha = 1;
+ [v setBackgroundColor:RGBACOLOR(255,255,255,1)];
+ [UIView animateWithDuration:speed delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+ v.layer.transform = CATransform3DMakeTranslation(-(spaceFromCurrent-30), 0, -300);
+ } completion:^(BOOL finished) {
+ //
+ }];
}else {
[v setBackgroundColor:RGBACOLOR(255,255,255,0.8)];
if (currentViewIndex == index-1 || currentViewIndex == index + 1) {
- v.alpha = 0.9;
- v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.8, 0.8, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-70), 0, -300));
+ [UIView animateWithDuration:speed delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+ v.alpha = 0.9;
+ v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.8, 0.8, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-70), 0, -300));
+ } completion:^(BOOL finished) {
+ //
+ }];
}else if (currentViewIndex == index-2 || currentViewIndex == index + 2) {
- v.alpha = 0.7;
- v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.7, 0.7, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-90), (currentViewIndex > index? -8:8), -300));
+ [UIView animateWithDuration:speed delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+ v.alpha = 0.7;
+ v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.7, 0.7, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-90), (currentViewIndex > index? -8:8), -300));
+ } completion:^(BOOL finished) {
+ //
+ }];
+
}else if (currentViewIndex == index-3 || currentViewIndex == index + 3) {
- v.alpha = 0.5;
- v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.6, 0.6, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-110), (currentViewIndex > index? -22:22), -300));
- }else if (currentViewIndex == index-4 || currentViewIndex == index + 4) {
- v.alpha = 0;
- v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.6, 0.6, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-130), (currentViewIndex > index? -38:38), -300));
- }else{
- v.alpha = 0;
- v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.6, 0.6, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-300), (currentViewIndex > index? -8:8), -300));
+
+ [UIView animateWithDuration:speed delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+ v.alpha = 0.5;
+ v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.6, 0.6, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-110), (currentViewIndex > index? -22:22), -300));
+ } completion:^(BOOL finished) {
+ //
+ }];
+
+
+ }else {
+
+ [UIView animateWithDuration:speed delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
+ v.alpha = 0;
+ v.layer.transform = CATransform3DConcat(CATransform3DMakeScale(0.6, 0.6, 1),CATransform3DMakeTranslation(-(spaceFromCurrent-130), (currentViewIndex > index? -38:38), -300));
+ } completion:^(BOOL finished) {
+ //
+ }];
+
+
}
}
currentViewIndex++;
}
- if(animated) [UIView commitAnimations];
+// if(animated) [UIView commitAnimations];
[self playSound];
}
+-(void)playSound {
+ AudioServicesPlaySystemSound(soundID);
+}
+
#pragma mark UIScrollView Delegate
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
@@ -127,7 +157,7 @@ - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
pos = yOffset;
CGFloat num = totalViews;
- CGFloat per = (scrollView.contentOffset.y) / (self.contentSize.height - currentSize.height);
+ CGFloat per = (scrollView.contentOffset.y) / (self.contentSize.height - (currentSize.height));
CGFloat ind = num * per;
CGFloat mi = ind / (totalViews/2);
@@ -141,8 +171,9 @@ - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
currentIndex = index;
- if(velocity < 180)
+ if(velocity < 180) {
[self animateToIndex:index animated:YES];
+ }
}
@@ -158,20 +189,6 @@ - (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOO
}
}
-- (void) snapToAlbum:(BOOL)animated{
-
- if (currentIndex < totalViews) {
- UIView *v = [views objectAtIndex:currentIndex];
-
- if((NSObject*)v!=[NSNull null]) {
- [self setContentOffset:CGPointMake(0, (v.center.y - (currentSize.height/2.2))) animated:animated];
-
- [self playSound];
- }
- }
-
-}
-
#pragma mark Touch Events
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
@@ -199,10 +216,7 @@ - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
if(currentTouch!= nil) currentTouch = nil;
}
-////////////////////////////////////////////////////////////////
-// public method
-////////////////////////////////////////////////////////////////
-
+#pragma mark Public Methods
- (void) bringViewAtIndexToFront:(int)index animated:(BOOL)animated{
if(index == currentIndex) return;
@@ -218,6 +232,20 @@ - (void) bringViewAtIndexToFront:(int)index animated:(BOOL)animated{
}
+- (void) snapToAlbum:(BOOL)animated{
+
+ if (currentIndex < totalViews) {
+ UIView *v = [views objectAtIndex:currentIndex];
+
+ if((NSObject*)v!=[NSNull null]) {
+ [self setContentOffset:CGPointMake(0, (v.center.y - (currentSize.height/2.2))) animated:animated];
+
+ [self playSound];
+ }
+ }
+
+}
+
- (void) addUserView:(UserBoxView*)userBoxView {
float ypos = 0;
@@ -245,10 +273,6 @@ -(void)jumpToLast:(BOOL)animated {
[self bringViewAtIndexToFront:lastIndex animated:animated];
}
--(void)playSound {
- AudioServicesPlaySystemSound(soundID);
-}
-
- (void) dealloc {
AudioServicesDisposeSystemSoundID(soundID);
self.scrollViewDelegate = nil;

0 comments on commit 1635224

Please sign in to comment.