English 中文(简体)
目 录
原标题:Objective C: Drop Area

i am trying to have a drop area of an item and when the item drops on the wrong area it will go back to its original position.

我的守则如下:

UITouch *touch =[[event allTouches] anyObject];
    CGPoint dropPoint = CGPointMake(60, 520);
    location = [touch locationInView:self.view];


if([touch view]==image1 && CGPointEqualToPoint(location, dropPoint)){
   [image1 setFrame:CGRectMake(60, 520, 150, 184)];
    return;
} else
{
    [dad setFrame:CGRectMake(530, 225, 150, 184)];
}

i 我认为,我的错误是,如果指挥指挥,在指挥之前必须确切地表明这一点,即点点上的位置是正确的吗?

现在我不知道如何确定......

事先得到帮助!

最佳回答

由于CGPoint使用CGFloats(这意味着该地点必须如此精确,我并不认为大多数用户能够这样做),我最好的猜测是,它会处理下点问题。 一种解决办法是利用CGRect和比较使用:

CGRectContainsPoint(dropRect, location);

注:比较:

[touch view] == image1

如果两点人提到同一物体(只要你知道UITouches的眼光财产会归还原先的看法,那么现在的感觉就会出现。

问题回答

This line

[touch view]==image1

compares the pointers not the objects to which they point. This may be your problem. An easy solution is to use the tag property for UIViews to keep track of which image is currently the view for touch.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签