Iphone &引用;“鬼矩形”;影响节目?

Iphone &引用;“鬼矩形”;影响节目?,iphone,ios,objective-c,frameworks,Iphone,Ios,Objective C,Frameworks,昨天有一个长方形卡在我的程序的上角,出于某种原因,无论我做什么,我都无法把它弄出来。今天我重新运行了程序,它消失了,但我相信它的内存仍然被卡住,因为它影响了我的代码 我试图检测矩形A(由加速度计移动)何时接触矩形B(随机放置;不动)。当A与B接触时不会发生任何事情,但是当我将A移动到上角时,它会连续运行if语句,直到我将其移开 这是代码,以备不时之需 @synthesize Button; @synthesize Rand; //Awaking the accelerometer -(void)

昨天有一个长方形卡在我的程序的上角,出于某种原因,无论我做什么,我都无法把它弄出来。今天我重新运行了程序,它消失了,但我相信它的内存仍然被卡住,因为它影响了我的代码

我试图检测矩形A(由加速度计移动)何时接触矩形B(随机放置;不动)。当A与B接触时不会发生任何事情,但是当我将A移动到上角时,它会连续运行if语句,直到我将其移开

这是代码,以备不时之需

@synthesize Button;
@synthesize Rand;
//Awaking the accelerometer
-(void) awakeaccelerometer
{
    [[UIAccelerometer sharedAccelerometer]setUpdateInterval:1.0/50.0];//<---Sensitivity
    [[UIAccelerometer sharedAccelerometer]setDelegate:self];

    NSLog(@"Accelerometer is awake");

    float randX = arc4random() % 320;
    float randY = arc4random() % 548;

    CGPoint randNewPlace = CGPointMake(randX, randY);
    Rand.center = randNewPlace;

}


//Controlling the accelerometer
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
#define MovingObjectRadius 4

    //Acceleration for player
    valueX = acceleration.x * 10; //speeds
    valueY = acceleration.y * -10; //speeds



    //Create new integers
    int newX = (int)(Button.center.x + valueX);
    int newY = (int)(Button.center.y + valueY);


    //Position Validate...This stops the movements from going past the screen; 320 pixels
    //For X
    if (newX > (320 - MovingObjectRadius))
    {
        newX = (320 - MovingObjectRadius);
    }

    if (newX < (0 + MovingObjectRadius))
    {
        newX = (0 + MovingObjectRadius);
    }

    //For Y
    if (newY > (548 - MovingObjectRadius))
    {
        newY = (548 - MovingObjectRadius);
    }

    if (newY < (0 + MovingObjectRadius))
    {
        newY = (0 + MovingObjectRadius);
    }



    //Make the new point
    CGPoint buttonNewCenter = CGPointMake(newX,newY);
    Button.center = buttonNewCenter;


    CGRect blockRect = CGRectMake(newX, newY, 20, 20);
    CGRect targetRect = CGRectMake(randX, randY, 20, 20);

    if (CGRectIntersectsRect(blockRect, targetRect))
        {
            float tnewX = arc4random() % 320;
            float tnewY = arc4random() % 548;

            CGPoint randNewPl = CGPointMake(tnewX, tnewY);
            Rand.center = randNewPl;
        }
}
@合成按钮;
@合成兰德;
//唤醒加速度计
-(无效)唤醒
{
[[UIAccelerator sharedAccelerometer]设置日期间隔:1.0/50.0];/(320-移动对象半径))
{
newX=(320-移动对象半径);
}
如果(newX<(0+移动对象半径))
{
newX=(0+移动对象半径);
}
//对于Y
if(newY>(548-移动对象半径))
{
newY=(548-移动对象半径);
}
如果(新的<(0+移动对象半径))
{
newY=(0+移动对象半径);
}
//提出新观点
CGPoint按钮newcenter=CGPointMake(newX,newY);
Button.center=buttonNewCenter;
CGRect blockRect=CGRectMake(newX,newY,20,20);
CGRect targetRect=CGRectMake(randX,randY,20,20);
if(CGRectIntersectsRect(blockRect,targetRect))
{
float tnewX=arc4random()%320;
float tnewY=arc4random()%548;
CGPoint randNewPl=CGPointMake(tnewX,tnewY);
Rand.center=randNewPl;
}
}

重影矩形?听起来你需要驱魔师?你试着问了吗?哈。是 啊但实际上,在上角没有任何东西,但每次我运行程序时,我的if语句都像循环一样播放(也就是说两个矩形相互接触…),直到我移开块为止。昨天一整日都有一个积木卡在那里,位置相同,尺寸也差不多。你是说“调用
加速计:didAccelerate:
方法”而不是“运行你的if语句”吗?