Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
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?
 
I made a table view and I have two questions.

1. Can I set background image to transparency in circle of attachment?

2. I used code as below to move that table view, but it never moved, can you help me?
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];
}
 

Attachments

  • SnapShot 2010-10-30 at 3.23.19.jpg
    SnapShot 2010-10-30 at 3.23.19.jpg
    40.7 KB · Views: 89
1) Probably. I think you need to turn off opaque.

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.
 
1) Probably. I think you need to turn off opaque.
Do you mean that table view's opaque? I off it, but the result is the same.

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.
I just want check if I can move it so that I selected simple way, like you said I will try gesture.

By the way, I found I can move it when I clicked out of table view, do you know why?
 

Attachments

  • SnapShot 2010-10-30 at 4.20.13.jpg
    SnapShot 2010-10-30 at 4.20.13.jpg
    70.9 KB · Views: 90
By the way, I found I can move it when I clicked out of table view, do you know why?
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.

Did you set the background color of the table to clearColor also? You might also need to set the backgroundView to nil.
 
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.
Your explain might be right.

Did you set the background color of the table to clearColor also? You might also need to set the backgroundView to nil.
backgroundView = nil doesn't work.
I also used code as below so that I can't use clearColor.
Code:
table.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon.png"]];
 
I got what I need with gestureRecognizer as below
Code:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[table addGestureRecognizer:panGesture];
[panGesture release];
But trans is still not clear:)
 
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.
 
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.
It is transparency.
 

Attachments

  • icon.png
    icon.png
    83.8 KB · Views: 300
How is the image displayed on screen? Is it in a view of it's own (say a UIImageView)? If so what is the background colour of the view? Is the view set to display it's background? What have you tried to solve this already?
 
Well, I used code as below to get transparency background image.
Code:
...
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];
...
 

Attachments

  • SnapShot 2010-10-31 at 17.58.45.jpg
    SnapShot 2010-10-31 at 17.58.45.jpg
    71.3 KB · Views: 93
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.