iphone - UIScrollView Subview Scaling -
i'm attempting scale uiscrollview's subviews, based off of how far away center of container. think i'm close, isn't quite right. views left of center line scaled bit less right.
-(void)scrollviewdidscroll:(uiscrollview *)scrollview { for( unsigned int i=0; i<[scrollview.subviews count]; i++ ) { uiview *v = [scrollview.subviews objectatindex:i]; // not quite right here float scale = 1. - ( abs(scrollview.center.x - ( v.center.x - scrollview.contentoffset.x ) ) / scrollview.contentsize.width/2 ); v.alpha = scale; v.transform = cgaffinetransformidentity; v.transform = cgaffinetransformscale(v.transform, scale, scale); } }
if has thoughts, i'd appreciate it, has been long day fighting this.
testing scale calculation can see there's wrong in first part of it. imagine following values: scrollview center x = 10 scrollview contentoffset x = 30 v1 center x = 5 v2 center x = 15
v1 , v2 mirrored (5 pixels left of center , 5 right of center), should return same scale value. if calculation code, returns 35 , 25, means calculation isn't right.
i'm not sure how want scale behave suggestion be:
float scale = 1. - ( (scrollview.contentoffset.x - abs( v.center.x - scrollview.center.x ) ) / scrollview.contentsize.width/2 );
edit: try one:
float scale = 1. - (abs( v.center.x - scrollview.center.x ) ) / scrollview.contentsize.width/2 );
there many ways of doing calculation. point should make sure operations giving expected results fake values, , yours not. dividend giving wrong results.
Comments
Post a Comment