I found iCardSort and I can move card on screen when I tap that card, I want to know how can I do it in my application, does anyone give me some hint or tips?
Thanks for your advise.Look at Apple's MoveMe sample code.
- (void)viewDidLoad {
[super viewDidLoad];
table = [[UITableView alloc] initWithFrame:CGRectMake(100, 100, 256, 256)];
table.multipleTouchEnabled = YES;
table.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon.png"]];
[self.view addSubview:table];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
table.center = location;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
Do you mean that table view's opaque? I off it, but the result is the same.1) Probably. I think you need to turn off opaque.
I just want check if I can move it so that I selected simple way, like you said I will try gesture.2) Few comments. Table views are scroll views and are probably quite complicated to make this work, if at all possible. I don't know. If you override one of the touches methods you need to override all four. Obviously a table view/scroll view needs to get its touches in order to work correctly so you'll need to pass the touches (or some of them) to the table view. You might also look at UIGestureRecognizer to implement this. The moveme sample code was written before gesture recognizers existed and using the touches methods is a bit old-fashioned. At any rate making a table view follow your finger is going to be more complicated than making a simple view follow your finger.
I'm not sure that the logic in your touchesBegan method is correct. Are you sure that the touches methods are being called? Can you log the location and see if it's what you expect? Are the touches methods in your view controller? If so I'm not sure that the table view will call them. They probably need to be in a tableview subclass. Using the gesture recognizers will avoid having to subclass the table view.
My guess is that you have added the touchesBegan to your view controller. The tableview already has its own touchesBegan method. If you touch the background view then the touch is sent to the view controller but if you touch the table the table swallows the touch. Not sure though.By the way, I found I can move it when I clicked out of table view, do you know why?
Your explain might be right.My guess is that you have added the touchesBegan to your view controller. The tableview already has its own touchesBegan method. If you touch the background view then the touch is sent to the view controller but if you touch the table the table swallows the touch. Not sure though.
backgroundView = nil doesn't work.Did you set the background color of the table to clearColor also? You might also need to set the backgroundView to nil.
table.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon.png"]];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[table addGestureRecognizer:panGesture];
[panGesture release];
It is transparency.I think you need transparency in your image. Is that corner black or transparent? If it is transparent then I think there may be a problem with using the pattern color. Instead you could set the backgroundView to an image view with this image in it.
...
table = [[UITableView alloc] initWithFrame:CGRectMake(100, 100, 256, 256)];
table.backgroundColor = [UIColor clearColor];
UIImage *back = [UIImage imageNamed:@"icon.png"];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:back];
table.backgroundView = backgroundView;
[backgroundView release];
[self.view addSubview:table];
...