In my program , I set replace image when I swipe for animation
cate 1.png -> cate2.png->cate3.png->cate1.png-> ~
and set changing label’s frame by using setframe.
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
int offsetx=(int)scrollView.contentOffset.x;
if(offsetx>0 && offsetx<20)
{
UIImage * image=[UIImage imageNamed:@"cate1.png"];
cateImageview.image=image;
UIFont * font=[UIFont systemFontOfSize:14];
[gameLabel setFont:font];
[gameLabel setFrame:CGRectMake(140,18,50,50)];
return ;
}
if(offsetx>20 && offsetx<40)
{
UIImage * image=[UIImage imageNamed:@"cate2.png"];
cateImageview.image=image;
[gameLabel setFrame:CGRectMake(122,16,50,50)];
return ;
}
if(offsetx>40 && offsetx<60)
{
UIImage * image=[UIImage imageNamed:@"cate3.png"];
cateImageview.image=image;
[gameLabel setFrame:CGRectMake(113,14,50,50)];
return ;
}
if( offsetx>60 && offsetx<80)
{
UIImage * image=[UIImage imageNamed:@"cate1.png"];
cateImageview.image=image;
[gameLabel setFrame:CGRectMake(103,12,50,50)];
return ;
}
if( offsetx>80 && offsetx<100)
{
UIImage * image=[UIImage imageNamed:@"cate2.png"];
cateImageview.image=image;
[gameLabel setFrame:CGRectMake(92,10,50,50)];
return ;
}
if( offsetx>100 && offsetx<120)
{
UIImage * image=[UIImage imageNamed:@"cate3.png"];
cateImageview.image=image;
[gameLabel setFrame:CGRectMake(83,8,50,50)];
return ;
}
.
.
.
if(offsetx >820 && offset <840)
.
.
}
-
Do using replace image way for animation have problem? I want to know a better way.
-
Do using label’s frame way for animation have problem? I want to know a better way.
-
label.frame=CGRectMake(~,~,~,~) vs [label setFrame:CGReckMake(~,~,~,~)]
Is there differences? what?
1. Animating Image
You can’t animate changing the image using the image property. If you want to fade the image between one and another you can add a second imageView on the same frame, above your imageView and animate its opacity from 0 to 1. Then when the animation finishes, remove the old imageView or change the image and remove the animated imageView.
2. Animating Frame
The frame is an animatable property but simply setting a new value won’t cause an animation. There is no problem using the frame to animate. Look into UIView animations for simple animations like this one:
3. Dot-notation or not
label.frame = ...;and[label setFrame:...];is exactly the same thing. Just two different ways of writing code.