Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-30-2010, 08:19 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
JMKit is on a distinguished road
Question Dragging multiple UIImageViews at the same time?

Hi all,
So I'm looking for a way two drag two (or more) UIImageViews around at the same time, I guess that's what's being done in games like air hockey where u have 2 people playing, each with there own 'paddle'


So far to get my my images, in this example pic1 and pic2 to move around I'm using this code:

Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	
	UITouch *touch = [[event allTouches] anyObject];
	if ([touch view] == pic1) {
		CGPoint location = [touch locationInView:self.view];
		pic1.center = location;
	}
	if ([touch view] == pic2) {
		CGPoint location = [touch locationInView:self.view];
		pic2.center = location;
	}
}
But obviously this just lets you drag one or the other, and while i'm dragging one I can't move the other at the same time.

Any help here would be greatly appreciated, i know this question has been asked before but I couldn't find the answer yet, so hopefully someone can point out something obvious i'm overlooking XD
JMKit is offline   Reply With Quote
Old 05-30-2010, 04:10 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 56
aloew is on a distinguished road
Default

UITouch *touch = [[event allTouches] anyObject]; takes one touch - in my opinion you should iterate over the set of touches in stead of just picking one.
Try to use
for(UITouch *touch in [event allTouches])
instead.

I implemented multi-touch handling in my app Personal Photo Clock by accident ;-). I added scrollviews for the digits and added the handlers to the scroll views.
I found out that all views respont to the dragging at the same time.
If the for does not work try to add the handlers to the UIViews....
__________________
TexturePacker - the best sprite sheet maker
PhysicsEditor - editor for box2d and chipmunk collision shapes
aloew is offline   Reply With Quote
Old 05-30-2010, 04:24 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
JMKit is on a distinguished road
Default

Quote:
Originally Posted by aloew View Post
UITouch *touch = [[event allTouches] anyObject]; takes one touch - in my opinion you should iterate over the set of touches in stead of just picking one.
Try to use
for(UITouch *touch in [event allTouches])
instead.

I implemented multi-touch handling in my app Personal Photo Clock by accident ;-). I added scrollviews for the digits and added the handlers to the scroll views.
I found out that all views respont to the dragging at the same time.
If the for does not work try to add the handlers to the UIViews....
Thanks for the reply,

Did you mean literally replace:
UITouch *touch = [[event allTouches] anyObject];
with
UITouch *touch in [event allTouches]

or do you mean to add the line:
'for(UITouch *touch in [event allTouches])' as written somewhere else?
JMKit is offline   Reply With Quote
Old 05-30-2010, 04:30 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 8
JMKit is on a distinguished road
Default

omg lol ok i figured it out.. so my code now looks like this:

Code:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	
	for(UITouch *touch in [event allTouches])
	if ([touch view] == pic1) {
		CGPoint location = [touch locationInView:self.view];
		pic1.center = location;
	}
	for(UITouch *touch in [event allTouches])
	if ([touch view] == pic2) {
		CGPoint location = [touch locationInView:self.view];
		pic2.center = location;
	}
}
and it works jus as i wanted
I'll have to buy your app soon to say thanks lol
JMKit is offline   Reply With Quote
Reply

Bookmarks

Tags
draggable, multiple, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 324
9 members and 315 guests
ajay123123, ashaman64, baja_yu, ChrisYates, HemiMG, newDev, Objective Zero, pkIDSF, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:54 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0