应用后,条件代码开始以不同的方式起作用 [英] After applying while condition code starts acting differently

查看:43
本文介绍了应用后,条件代码开始以不同的方式起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款游戏,希望图像逐渐缩小。我可以在代码正常运行时逐渐减小帧的大小。 [我已经使用过CGAffineTransform,它不符合我的要求。]

I'm developing a game in which I want my image to reduce in size gradually. I'm reducing the frame size gradually in my code when it works fine. [I've already used CGAffineTransform and it doesn't suit my requirement.]

-(void)function     
{
    ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);

    if(ravanImage1.center.y>=300&&ravanImage1.center.y<=370)
    {
        q=60;
        z=60;
        ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
    }   

    if(ravanImage1.center.y>=230&&ravanImage1.center.y<=299)
    {
        q=40;
        z=40;
        ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
    }

    if(ravanImage1.center.y>=150&&ravanImage1.center.y<=229)
    {   
        q=20;
        z=20;
        ravanImage1.frame=CGRectMake(150,((ravanImage1.frame.origin.y)-5),q,z);
    }
}

但是当我对相同的代码应用while循环时指定惠瑟在什么位置停止缩小帧(到达该点时),它不会一点一点地显示图像帧减少,否则会显示一点,而是直接将图像放置在终点适当的框架。
我希望它能像没有while循环那样分散显示,即一点一点地减少。是的,在调试时会正确地逐步完成所有步骤。
有人可以帮帮我吗?

But when I apply a while loop for the same code specifying wheather at what point to stop reducing the frame("while that point isn't reached"), it doesn't show the image frame reduction little by little as it shows it otherwise, but directly places the image at the end point with proper frame. I want it to get displyed the way it gets without the while loop i.e. reduction little by little. Yes, while debugging it steps through all the steps properly. Can anybody please help me?

推荐答案

正如其他人指出的那样,手动调整视图框架会给你的表现糟糕。如果您确实不想使用标准的UIView动画块来更改视图,则可以通过使用应用于视图图层的CAKeyframeAnimation来指定边界大小值来进行动画处理。

As others have pointed out, manually adjusting the frame of your view will give you terrible performance. If you really don't want to use a standard UIView animation block for changing your view, you can specify bounds size values to animate through using a CAKeyframeAnimation applied to your view's layer:

CAKeyframeAnimation * customSizeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"bounds.size"];
NSArray *sizeValues = [NSArray arrayWithObjects:[NSValue valueWithCGSize:size1], [NSValue valueWithCGSize:size2], [NSValue valueWithCGSize:size3], nil];
[customSizeAnimation setValues:frameValues];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:1.0f], nil]; 
[customSizeAnimation setKeyTimes:times];
customSizeAnimation.fillMode = kCAFillModeForwards;
customSizeAnimation.removedOnCompletion = NO;
[view.layer addAnimation: customSizeAnimation forKey:@"customSizeAnimation"];

此动画将以size1开始,在动画的中点经过size2,并结束于尺寸3。您可以为动画设置任意数量的关键帧和时间,因此您应该能够实现所需的效果

This animation will start at size1, pass through size2 at the midway point in the animation, and end at size3. You can have an arbitrary number of key frames and times for your animation, so you should be able to achieve the effect you desire

编辑(1/5/2010):删除了kCAAnimationPaced作为CalculationMode,这将导致忽略关键时间。另外,我忘记了框架是派生属性,所以您需要制作动画,例如边界大小。

EDIT (1/5/2010): Removed kCAAnimationPaced as a calculationMode, which would cause the key times to be ignored. Also, I forgot that frame was a derived property, so you need to animate something like the bounds size instead.

这篇关于应用后,条件代码开始以不同的方式起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆