@property int currentIndex;
@property (nonatomic) CGFloat beginOffset;
@property (nonatomic) NSInteger currentPage;
#define finalAngel 30.0f
#define perspective 1.0/-600
#define finalAlpha 0.6f
#define zoom 0.88
#define finalAlpha 0.6f
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = scrollView.frame.size.width;
CGFloat offset = scrollView.contentOffset.x;
CGFloat percent = MIN(1,fabs((offset - self.beginOffset)/pageWidth));
UIImageView *sourceView = scrollView.subviews[self.currentIndex];
UIImageView *destView = nil;
int nextIndex = (offset - self.beginOffset)>0? self.currentIndex+1 :self.currentIndex-1;
if(nextIndex>=0 && nextIndex<3){
destView = scrollView.subviews[nextIndex];
}
if(offset - self.beginOffset>0) {
}
CGFloat sourceViewZoom =1-(1-zoom)*percent;
sourceView.transform=CGAffineTransformMakeScale(sourceViewZoom, sourceViewZoom);
sourceView.alpha = 1 - percent*(1-finalAlpha);
if(destView){
CGFloat destViewZoom = zoom+(1-zoom)*percent;
destView.transform=CGAffineTransformMakeScale(destViewZoom, destViewZoom);
destView.alpha = finalAlpha + (1-finalAlpha)*percent;
}
NSLog(@"---------------%f--------------%d",offset,_currentIndex);
CATransform3D transform = CATransform3DIdentity;
transform.m34 = perspective;
CGFloat angle = finalAngel * M_PI / 180.0f*percent;
if(offset - self.beginOffset<0){
angle = -angle;
}
transform = CATransform3DRotate(transform, angle , 0.0f, 1.0f, 0.0f);
sourceView.layer.transform = transform;
sourceView.alpha = 1 - percent*(1-finalAlpha);
if(destView){
CATransform3D transform = CATransform3DIdentity;
transform.m34 = perspective;
CGFloat angle = - finalAngel * M_PI / 180.0f * (1-percent);
if(offset - self.beginOffset<0){
angle = -angle;
}
transform = CATransform3DRotate(transform, angle , 0.0f, 1.0f, 0.0f);
destView.layer.transform = transform;
destView.alpha = finalAlpha + (1-finalAlpha)*percent;
}
}
-(void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.beginOffset = scrollView.contentOffset.x;
CGFloat pageWidth = scrollView.frame.size.width;
CGFloat offset = scrollView.contentOffset.x;
self.currentIndex = floor((offset - pageWidth /3) / pageWidth) + 1;
}