Multi touch is not working perfectly on UIImageView - iphone

I am doing multi touch on UImageView means zoom in and zoom out on image view. I am using followng code but it doesn't work very well. Can anyone look at this code,
#import "ZoomingImageView.h"
#implementation ZoomingImageView
#synthesize zoomed;
#synthesize moved;
define HORIZ_SWIPE_DRAG_MIN 24
define VERT_SWIPE_DRAG_MAX 24
define TAP_MIN_DRAG 10
CGPoint startTouchPosition;
CGFloat initialDistance;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
moved = NO;
zoomed = NO;
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
}
- (void)dealloc {
if([timer isValid])
[timer invalidate];
[super dealloc];
}
- (void) setImage: (UIImage*)img
{
zoomed = NO;
moved = NO;
self.transform = CGAffineTransformIdentity;
[super setImage:img];
}
- (CGFloat)distanceBetweenTwoPoints:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {
float x = toPoint.x - fromPoint.x;
float y = toPoint.y - fromPoint.y;
return sqrt(x * x + y * y);
}
- (CGFloat)scaleAmount: (CGFloat)delta {
CGFloat pix = sqrt(self.frame.size.width * self.frame.size.height);
CGFloat scale = 1.0 + (delta / pix);
return scale;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if([timer isValid])
[timer invalidate];
moved = NO;
switch ([touches count]) {
case 1:
{
// single touch
UITouch * touch = [touches anyObject];
startTouchPosition = [touch locationInView:self];
initialDistance = -1;
break;
}
default:
{
// multi touch
UITouch *touch1 = [[touches allObjects] objectAtIndex:0];
UITouch *touch2 = [[touches allObjects] objectAtIndex:1];
initialDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:self]
toPoint:[touch2 locationInView:self]];
break;
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch1 = [[touches allObjects] objectAtIndex:0];
if([timer isValid])
[timer invalidate];
/*if ([touches count] == 1) {
CGPoint pos = [touch1 locationInView:self];
self.transform = CGAffineTransformTranslate(self.transform, pos.x - startTouchPosition.x, pos.y - startTouchPosition.y);
moved = YES;
return;
}****/
if ((initialDistance > 0) && ([touches count] > 1)) {
UITouch *touch2 = [[touches allObjects] objectAtIndex:1];
CGFloat currentDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:self]
toPoint:[touch2 locationInView:self]];
CGFloat movement = currentDistance - initialDistance;
NSLog(#"Touch moved: %f", movement);
CGFloat scale = [self scaleAmount: movement];
self.transform = CGAffineTransformScale(self.transform, scale, scale);
// }
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch1 = [[touches allObjects] objectAtIndex:0];
if ([touches count] == 1) {
// double tap to reset to default size
if ([touch1 tapCount] > 1) {
if (zoomed) {
self.transform = CGAffineTransformIdentity;
moved = NO;
zoomed = NO;
}
return;
}
}
else {
// multi-touch
UITouch *touch2 = [[touches allObjects] objectAtIndex:1];
CGFloat finalDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:self]
toPoint:[touch2 locationInView:self]];
CGFloat movement = finalDistance - initialDistance;
NSLog(#"Final Distance: %f, movement=%f",finalDistance,movement);
if (movement != 0) {
CGFloat scale = [self scaleAmount: movement];
self.transform = CGAffineTransformScale(self.transform, scale, scale);
NSLog(#"Scaling: %f", scale);
zoomed = YES;
}
}
}
- (void)singleTap: (NSTimer*)theTimer {
// must override
}
- (void)animateSwipe: (int) direction {
// must override
}
It is not working fine on device. can anyone tell that where i am wrong.

When you use any CGAffinTransform.... the value of the frame property becomes undefined. In your code you are using the frame.size.width and frame.size.height to calculate the change in size. After the first iteration of CGAffinTransformScale you would not get the right scale factor. According to the documentation bounds would be the right property for scale calculations.

Related

Dragging an Image View

I am trying to drag an image view. I have got little bit of success in doing so, but it is not behaving as i want. I wish that it should move only if touch inside the image and drag it.
But it is moving even if I am touching and dragging from anywhere on the screen.
I have written code like this:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//retrieve touch point
CGPoint pt= [[ touches anyObject] locationInView:[self.view.subviews objectAtIndex:0]];
startLocation = pt;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView: [self.view.subviews objectAtIndex:0]];
CGRect frame = [[self.view.subviews objectAtIndex:0]frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[[self.view.subviews objectAtIndex:0] setFrame: frame];
}
The return value of locationInView method is point relative to the view frame. check it is or not in the view frame first.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect targetFrame = [self.view.subviews objectAtIndex:0].frame;
//retrieve touch point
CGPoint pt= [[ touches anyObject] locationInView:[self.view.subviews objectAtIndex:0]];
//check if the point in the view frame
if (pt.x < 0 || pt.x > targetFrame.size.width || pt.y < 0 || pt.y > targetFrame.size.height)
{
isInTargetFrame = NO;
}
else
{
isInTargetFrame = YES;
startLocation = pt;
}
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
if(!isInTargetFrame)
{
return;
}
//move your view here...
}
Try something like this:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//retrieve touch point
startLocation = [[ touches anyObject] locationInView:self.view];
// Now here check to make sure that start location is within the frame of
// your subview [self.view.subviews objectAtIndex:0]
// if it is you need to have a property like dragging = YES
// Then in touches ended you set dragging = NO
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView: [self.view.subviews objectAtIndex:0]];
CGRect frame = [[self.view.subviews objectAtIndex:0]frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[[self.view.subviews objectAtIndex:0] setFrame: frame];

Level Selector - Cocos2d

I'm trying to add 10 levels and 1 per page, which is 10 pages. How can I use this code to do that? Right now it only has two pages. Can anyone help?
-(id) init
{
if ((self = [super init]))
{
CGSize s = [[CCDirector sharedDirector] winSize];
self.isTouchEnabled = YES;
isDragging = NO;
lastX = 0.0f;
xVel = 0.0f;
contentWidth = s.width * 10.0;
currentPage = 0;
// main scrolling layer - add as child to this page layer.
scrollLayer = [[[LevelScene alloc] init] autorelease];
scrollLayer.anchorPoint = ccp(0, 1);
scrollLayer.position = ccp(0, 0);
[self addChild:scrollLayer];
[self schedule:#selector(moveTick:) interval:0.02f];
}
return self;
}
- (void) moveTick: (ccTime)dt
{
float friction = 0.99f;
CGSize s = [[CCDirector sharedDirector] winSize];
if (!isDragging)
{
// inertia
xVel *= friction;
CGPoint pos = scrollLayer.position;
pos.x += xVel;
// to stop at bounds
pos.x = MAX(-s.width, pos.x);
pos.x = MIN(0, pos.x);
if (pos.x == -s.width)
{
xVel = 0;
currentPage = 1;
}
if (pos.x == 0)
{
xVel = 0;
currentPage = 0;
}
// snap to page by quickly moving to it: e.g.: xVel = 40
if (fabsf(xVel) < 10)
{
if (pos.x < -s.width/2.0)
{
xVel = -40;
}
else {
xVel = 40;
}
}
scrollLayer.position = pos;
}
else {
xVel = (scrollLayer.position.x - lastX)/2.0;
lastX = scrollLayer.position.x;
}
}
- (void) ccTouchesBegan: (NSSet *)touches withEvent: (UIEvent *)event
{
isDragging = YES;
}
- (void) ccTouchesMoved: (NSSet *)touches withEvent: (UIEvent *)event
{
CGSize s = [[CCDirector sharedDirector] winSize];
UITouch *touch = [touches anyObject];
// simple position update
CGPoint a = [[CCDirector sharedDirector] convertToGL:[touch previousLocationInView:touch.view]];
CGPoint b = [[CCDirector sharedDirector] convertToGL:[touch locationInView:touch.view]];
CGPoint nowPosition = scrollLayer.position;
nowPosition.x += (b.x - a.x);
nowPosition.x = MAX(-s.width, nowPosition.x);
nowPosition.x = MIN(0, nowPosition.x);
scrollLayer.position = nowPosition;
}
- (void) ccTouchesEnded: (NSSet *)touches withEvent: (UIEvent *)event
{
isDragging = NO;
}
Any help is greatly appreciated! Thanks!
Jon, it seems like you're trying to recreate a UIScrollView in cocos2d. If that's the case, might I suggest using an existing open source project known as CCScrollLayer (HERE) Out of the box it should do everything you need to do and is pretty easy to extend to meet your needs better.

TableView didSelectRowAtIndexPath Not Being Called

On a UITableView, I used Custom Cells with this code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.contentView];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.contentView];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if(deltaX < kMinimumGestureLength && deltaY < kMaximumVariance&&!swiped){
//do something
NSLog(#"Tapped %d",indexRow);
//return YES;
} else if(deltaX < kMinimumGestureLength && deltaY < kMaximumVariance&&swiped) {
swiped = FALSE;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.contentView];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
//do something
NSLog(#"Swiped %d",indexRow);
gestureStartPoint = [touch locationInView:self.contentView];
swiped = TRUE;
}
else if(deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
//do something
}
}
Before I added this, didSelectRowAtIndexPath was being called, however, now it is not. I can comment out the section and it works fine. Anyone know a way to fix this?
EDIT: Posting the working code
Customcell.h
#define kMinimumGestureLength 30
#define kMaximumVariance 5
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface CustomCell : UITableViewCell {
UILabel *primaryLabel;
UILabel *secondaryLabel;
UIImageView *myImageView;
CGPoint gestureStartPoint;
int indexRow;
BOOL swiped;
}
#property(nonatomic,retain)UILabel *primaryLabel;
#property(nonatomic,retain)UILabel *secondaryLabel;
#property(nonatomic,retain)UIImageView *myImageView;
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize primaryLabel,secondaryLabel,myImageView;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,0, 50, 50);
myImageView.frame = frame;
frame= CGRectMake(boundsX+70 ,5, 200, 25);
primaryLabel.frame = frame;
frame= CGRectMake(boundsX+70 ,30, 100, 15);
secondaryLabel.frame = frame;
}
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier indexd:(int)indexd {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:14];
secondaryLabel = [[UILabel alloc]init];
secondaryLabel.textAlignment = UITextAlignmentLeft;
secondaryLabel.font = [UIFont systemFontOfSize:8];
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];
[self.contentView addSubview:myImageView];
indexRow = indexd;
}
swiped = false;
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.contentView];
// [super touchesbegan];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.contentView];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if(deltaX < kMinimumGestureLength && deltaY < kMaximumVariance&&!swiped){
//do something
NSLog(#"Tapped %d",indexRow);
[super touchesEnded:touches withEvent:event];
//return YES;
} else if(deltaX < kMinimumGestureLength && deltaY < kMaximumVariance&&swiped) {
swiped = FALSE;
}
//[super touchesEnded];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.contentView];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
//do something
NSLog(#"Swiped %d",indexRow);
gestureStartPoint = [touch locationInView:self.contentView];
swiped = TRUE;
//[self.superview.dataSource editCell];
}
else if(deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){
//do something
}
//[super touchesMoved];
}
#end
I'm not 100% certain, but I think you need to call the super methods in order to continue to have the default behavior.
[super touchesBegan:...];
[super touchesEnded:...];
[super touchesMoved:...];
Each in it's own method.
This seems to be similar to this question. try calling the parent methods with [super touchesbegan] et al.

touch events problem

I found a very strange problem while handling touch events. The idea of an app is that i have an ImageView which contains a circle with text, that the user can rotate.
I've implemented a custom UIScrollView subclass to contain circle image. There i implemented methods touchesBegan, touchesMoved and touchesEnded in order to rotate my circle when user drags it left or right. Everything works fine, but when you try to drag it with one finger very fast from one side to another and in opposite direction, methods touchesBegan and touchesEnded are called different number of times. For example touchesBegan was called 1 time and touchesEnded 2 - 3 times. How can it be?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if([[event touchesForView:self] count]==1){
touchPoint = [[touches anyObject] locationInView:self];
previousTouchPoint = touchPoint;
angle = 0;
if (((touchPoint.x > 160)&&(touchPoint.y < 210))||((touchPoint.x < 160)&&(touchPoint.y > 210))) {
leftRotation = YES;
}
else {
leftRotation = NO;
}
currentMoveAngle = 0;
}
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
if([[event touchesForView:self] count] == 1){
CGPoint newPoint = [[touches anyObject] locationInView:self];
CGPoint origin;
if (self.tag == 2) {
origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
}
else {
origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
}
previousTouchPoint.x -= origin.x;
previousTouchPoint.y -= origin.y;
CGPoint second = newPoint;
second.x -= origin.x;
second.y -= origin.y;
CGFloat rotationAngle = [self rotationFromFirstPoint:previousTouchPoint toSecondPoint:second];
previousTouchPoint = newPoint;
[self rotateContentToAngle:rotationAngle animated:NO];
currentMoveAngle += rotationAngle;
}
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
if ([[event touchesForView:self] count] == 1){
rotating = YES;
CGFloat rotationAngle;
CGPoint origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
CGPoint lastPoint = [[touches anyObject] locationInView:self];
CGPoint touchP = touchPoint;
if ((touchP.x != lastPoint.x)||(touchP.y != lastPoint.y)) {
touchP.x -= origin.x;
touchP.y -= origin.y;
lastPoint.x -= origin.x;
lastPoint.y -= origin.y;
if (fabs(currentMoveAngle)>M_PI/6) {
NSInteger index = (int)trunc(currentMoveAngle/(M_PI/3));
currentMoveAngle-=(M_PI/3)*index;
NSLog(#"rotation index: %i",index);
}
if (leftRotation) {
rotationAngle = M_PI/3;
rotationAngle-=currentMoveAngle;
}
else {
rotationAngle = (-1)*M_PI/3;
rotationAngle-=currentMoveAngle;
}
[self rotateContentToAngle:rotationAngle animated:YES];
}
}
}
UIScrollView handle touch event very badly.... may be it is happening because of dragging of scrollView.
try this
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (!self.dragging){
if([[event touchesForView:self] count]==1){
touchPoint = [[touches anyObject] locationInView:self];
previousTouchPoint = touchPoint;
angle = 0;
if (((touchPoint.x > 160)&&(touchPoint.y < 210))||((touchPoint.x < 160)&&(touchPoint.y > 210))) {
leftRotation = YES;
}
else {
leftRotation = NO;
}
currentMoveAngle = 0;
}
}
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
if (!self.dragging){
if([[event touchesForView:self] count] == 1){
CGPoint newPoint = [[touches anyObject] locationInView:self];
CGPoint origin;
if (self.tag == 2) {
origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
}
else {
origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
}
previousTouchPoint.x -= origin.x;
previousTouchPoint.y -= origin.y;
CGPoint second = newPoint;
second.x -= origin.x;
second.y -= origin.y;
CGFloat rotationAngle = [self rotationFromFirstPoint:previousTouchPoint toSecondPoint:second];
previousTouchPoint = newPoint;
[self rotateContentToAngle:rotationAngle animated:NO];
currentMoveAngle += rotationAngle;
}
}
}
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
if (!self.dragging){
if ([[event touchesForView:self] count] == 1){
rotating = YES;
CGFloat rotationAngle;
CGPoint origin = CGPointMake(self.bounds.origin.x+self.bounds.size.width*0.5, 215);
CGPoint lastPoint = [[touches anyObject] locationInView:self];
CGPoint touchP = touchPoint;
if ((touchP.x != lastPoint.x)||(touchP.y != lastPoint.y)) {
touchP.x -= origin.x;
touchP.y -= origin.y;
lastPoint.x -= origin.x;
lastPoint.y -= origin.y;
if (fabs(currentMoveAngle)>M_PI/6) {
NSInteger index = (int)trunc(currentMoveAngle/(M_PI/3));
currentMoveAngle-=(M_PI/3)*index;
NSLog(#"rotation index: %i",index);
}
if (leftRotation) {
rotationAngle = M_PI/3;
rotationAngle-=currentMoveAngle;
}
else {
rotationAngle = (-1)*M_PI/3;
rotationAngle-=currentMoveAngle;
}
[self rotateContentToAngle:rotationAngle animated:YES];
}
} }
}
or make scrollingEnabled property NO.

How to check whether a CGPoint is inside a UIImageView?

In touchesBegan:
CGPoint touch_point = [[touches anyObject] locationInView:self.view];
There are tens of UIImageView around, stored in a NSMutableArray images. I'd like to know is there a built-in function to check if a CGPoint (touch_point) is inside one of the images, e.g.:
for (UIImageView *image in images) {
// how to test if touch_point is tapped on a image?
}
Thanks
Follow up:
For unknown reason, pointInside never returns true. Here is the full code.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
touch_point = [touch locationInView:self.view];
for (UIImageView *image in piece_images) {
if ([image pointInside:touch_point withEvent:event]) {
image.hidden = YES;
} else {
image.hidden = NO;
}
NSLog(#"image %.0f %.0f touch %.0f %.0f", image.center.x, image.center.y, touch_point.x, touch_point.y);
}
}
although I can see the two points are sometimes identical in the NSLog output.
I also tried:
if ([image pointInside:touch_point withEvent:nil])
the result is the same. never returns a true.
To eliminate the chance of anything goes with with the images. I tried the following:
if (YES or [image pointInside:touch_point withEvent:event])
all images are hidden after the first click on screen.
EDIT 2:
Really weird. Even I hard coded this:
point.x = image.center.x;
point.y = image.center.y;
the code becomes:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point; // = [touch locationInView:self.view];
for (UIImageView *image in piece_images) {
point.x = image.center.x;
point.y = image.center.y;
if ([image pointInside:point withEvent:event]) {
image.hidden = YES;
NSLog(#"YES");
} else {
image.hidden = NO;
NSLog(#"NO");
}
NSLog(#"image %.0f %.0f touch %.0f %.0f", image.center.x, image.center.y, point.x, point.y);
}
}
pointInside always returns false ...
Sounds to me like the problem is you need to convert coordinates from your view's coordinates to the UIImageView's coordinates. You can use UIView's convertPoint method.
Try replacing
if ([image pointInside:touch_point withEvent:event]) {
with
if ([image pointInside: [self.view convertPoint:touch_point toView: image] withEvent:event]) {
(Note that you are allowed to pass nil instead of event.)
I guess this is a bit late for the questioner, but I hope it is of use to someone.
if ([image pointInside:touch_point withEvent:event]) {
// Point inside
}else {
// Point isn't inside
}
In this case event is taken from :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
for (UIImageView *piece in piece_images) {
CGFloat x_min = piece.center.x - (piece.bounds.size.width / 2);
CGFloat x_max = x_min + piece.bounds.size.width;
CGFloat y_min = piece.center.y - (piece.bounds.size.height / 2);
CGFloat y_max = y_min + piece.bounds.size.height;
if (point.x > x_min && point.x < x_max && point.y > y_min && point.y < y_max ) {
piece.hidden = YES;
} else {
piece.hidden = NO;
}
}
}
too bad, I have do it myself...
it's OS 3.2, XCode 3.2.2, tried both on simulator and iPad