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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-04-2011, 11:08 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 2
seagulljl is on a distinguished road
Question How to get the animated object's position in the middle of the animation

I'm a new developer. My question is: is there a direct way to get the x,y position of an animated view in the middle of the animation?
I have this code (from the Stanford iPhone course in youtube) that moves the stalker UIView to the position of the touch:
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [UIView beginAnimations:@"stalk" context:nil];
    UITouch *touch = [touches anyObject];
    [UIView setAnimationDuration:10];
    [UIView setAnimationBeginsFromCurrentState:YES];
    stalker.center = [touch locationInView:self];
    [UIView commitAnimations];
}
I want to modify the code such that stalker will not move to the touch location but to a different location I want to calculate, which is relative on the stalker view position at the time of the touch.
It should be possible to do by calculating the time passed from the beginning of the animation till the touch, but I want to ask if there's a more direct way. I assume that the current x,y are stored somewhere under the hood - the question is how to access them.
Thanks!
seagulljl is offline   Reply With Quote
Old 11-21-2011, 08:58 AM   #2 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

There is no way that I know of that can do what you want. block animations like this are applied IMMEDIATELY when u set .center = location, only the iOS plays it out according to your animation settings.

I'd suggest you to use NSTimers and gradually moving the object by a speed variable. Then you can evaluate the object location at anytime as you please.
rocotilos is offline   Reply With Quote
Old 11-22-2011, 05:26 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
There is no way that I know of that can do what you want. block animations like this are applied IMMEDIATELY when u set .center = location, only the iOS plays it out according to your animation settings.

I'd suggest you to use NSTimers and gradually moving the object by a speed variable. Then you can evaluate the object location at anytime as you please.
Actually, Core Animation has three "layers": model, presentation and render. Model is where the changes are applied instantly, and that is what you get when you ask for the layer of an UIView. However, you can get the presentation layer of a CALayer just by calling [layer presentationLayer], and the presentation layer will have all values set according to the animation(s) in progress, so you can query them there.
fiftysixty is offline   Reply With Quote
Old 11-23-2011, 11:56 PM   #4 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Quote:
Originally Posted by fiftysixty View Post
Actually, Core Animation has three "layers": model, presentation and render. Model is where the changes are applied instantly, and that is what you get when you ask for the layer of an UIView. However, you can get the presentation layer of a CALayer just by calling [layer presentationLayer], and the presentation layer will have all values set according to the animation(s) in progress, so you can query them there.
Hm. I didn't know that. Thanks for telling me. You're awesome!
rocotilos is offline   Reply With Quote
Reply

Bookmarks

Tags
animation

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: 376
10 members and 366 guests
apatsufas, comicool, Creativ, Dalia, dansparrow, LunarMoon, mer10, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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