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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 11-29-2009, 11:52 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 14
Default Need advice on touchesMoved and a UIImageView

My wife has commented on my loss of hair the past 2 days on this. I took the project "Which Way Is Up" from iPhone Cookbook and thought about making a learning app that was like Twister/Life/boardgame where you flick the spinner and it spins to whatever slot. I just took the app in the book and modified it.

It's real simple in all you do is move your finger across the UIViewController and the centered UIImageView moves. I store the last 5 touch events in a struct array and get the average distance, time and get speed. I then use that calc to fire off a timer so that when they release their finger, the arrow spins relative to swipe.

Problem is, while touchesMoved is handled, the image seems to be in a context or something, not really updating as you let off your finger, it snaps back to the beginning pos, then moves on my timer.

LOL seems so awefully simple to just update a windows pos on the fly LOL


here's the setup..

Code:
- ( void ) loadView
{
...
gView = [ [ [ UIImageView alloc ] initWithFrame : CGRectMake ( 0.0, 0.0,  rect.size.width / 3 , rect.size.width - 25 ) ] retain ] ;
[ gView setCenter : axis  ] ;
[ gView setImage :[ UIImage imageNamed : @"arrow.png" ] ] ;
[ self.view addSubview : gView ] ;
...
}

By getting the origin.x and origin.y after the affinetransform, I found the pos updates and I can copy those values to later apply to the UIImage to update it. drawRect is not something Ive done in iPhone and seemed alot of extra work just to update a windows pos, so I figured this would be quick and easy.

things ive tried...

Code:
		deltaX = gView.frame.size.width ;
		deltaY = gView.frame.size.height ;
		CGFloat z = gView.layer.zPosition ;


gView.transform = CGAffineTransformMakeRotation ( degreesToRadian(angleDelta) ) ;

		CGRect gFrame = gView.frame ;
		gFrame.size.width = deltaX ;
		gFrame.size.height = deltaY ;

/**********
Cant find the proper way to set z Pos on a cgrect frame
***********/

		gView.layer.frame = gFrame ;
this makes the png move arond the z axis also and zoom in/out etc.

so, I tried this...

Code:
[gView.layer setValue : [NSNumber numberWithFloat:gFrame.origin.x] forKeyPath : @"transform.rotation.x"];
[gView.layer setValue : [NSNumber numberWithFloat:gFrame.origin.y] forKeyPath : @"transform.rotation.y"];
[gView.layer setValue : [NSNumber numberWithFloat:z] forKeyPath : @"transform.rotation.z"];
turns ok, but its in 3d, i want it to turn flat.

I cant set the bounds or pos on the frame, not enough xp I guess. But this is something that seems so very simple and the app is multi threaded with many timers, something so very simple stumbling me up is frustrating. Anyone wanna give a brother a hand in figuring this out?

Thanks
Enoch is offline   Reply With Quote
Old 12-02-2009, 07:27 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 14
Default

Puzzled as to why I cant get any help on any of my posts, did I say something wrong?


BTW - I def tried to find the answer on my own and came across all 404s for the vid tutorial "Touches and UIImageView"

Tried the drawRect much simpler than I anticipated but I still can't get the image to update its coords while touchesMoved is being handled. Figured I'd go ahead and just set the imageview manually after moved with touchesEnded, still snaps back. So, why not just create a whole new UIImageView with the updated pos, remove the original from superview and add the new imageview as a subview to self. Still snaps back.

Last edited by Enoch; 12-02-2009 at 07:56 PM.
Enoch is offline   Reply With Quote
Old 12-02-2009, 08:49 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 14
Default

Reading another board, someone said UIImageViews could only be moved thru the .frame prop. So after doing the same transform as above and storing the virtual pos, I tried this...

Code:
UIImageView * gView ;

- ( void ) touchesEnded : (NSSet*) touches withEvent : (UIEvent*) event
{
   CGRect r = [[UIScreen mainScreen] bounds ] ;
   gView.frame = CGRectMake(0, 0, r.size.width / 3, r.size.width - 25) ; 
}
The image view disappears.
Enoch is offline   Reply With Quote
Old 12-03-2009, 07:41 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 14
Default

Found my own work around solution and figure I'd post it for any future references as don't you hate unsolved links from google?

I was transforming the imageview by the degree during touchesMoved, so I just copied that each time to a CGFloat property.

Then at touchesEnded -

gView.transform = CGAffineTransformMakeRotation(endDegree) ;

It haps so fast you can't tell and it makes the image appear where the moved transforms last left it. Put in a min swipe distance check also or it looks dorky when you just touch the screen and let off, your image looks like a crack head.

peace
Enoch is offline   Reply With Quote
Reply

Bookmarks

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: 607
14 members and 593 guests
brianmethod, BrianSlick, dacapo, devangvyas, djohnson, Duncan C, emerldfds, holisticni8, learningtocode, linkmx, mollysalomons, Rudy, sudama, vikinara
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,773
Threads: 89,203
Posts: 380,580
Top Poster: BrianSlick (7,129)
Welcome to our newest member, holisticni8
Powered by vBadvanced CMPS v3.1.0

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