0
我正在使用一個應用程序,在那個圖像是使用動畫從屏幕的頂部到底部進行動畫。需要動畫時獲得圖像的幀座標
代碼:
- (void)onTimer
{
// build a view from our flake image
flakeView = [[UIImageView alloc] initWithImage:flakeImage];
flakeView.backgroundColor=[UIColor blueColor];
// use the random() function to randomize up our flake attributes
int startX =round(random() % 460);
printf("\n ===== startX :%d",startX);
int endX = round(random() % 460);
printf("\n ===== endX :%d",endX);
double scale = 1/round(random() % 100) - 1.0;
double speed = 1/round(random() %100) + 1.0;
// set the flake start position
flakeView.frame = CGRectMake(startX, -100.0, 25.0 * scale, 25.0 * scale);
flakeView.alpha = 1.0;
// put the flake in our main view
[mView addSubview:flakeView];
[UIView beginAnimations:nil context:flakeView];
[UIView setAnimationDuration:20 * speed];
// code to get current position of image on view
CALayer mainLayer = flakeView.layer.presentationLayer;
CGRect layerFrame = mainLayer.frame;
BOOL intersects = CGRectIntersectsRect(layerFrame, dragger.frame);
// end position on screen
flakeView.frame = CGRectMake(endX, 500.0, 15.0 * scale, 15.0 * scale);
// set a stop callback so we can cleanup the flake when it reaches the
// end of its animation
[UIView setAnimationDidStopSelector:@selector(onAnimationComplete:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (id)init
{
if(self = [super init])
{
mView = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,440)];
mView.backgroundColor = [UIColor whiteColor];
mainLayer =[CALayer layer];
// load our flake image we will use the same image over and over
flakeImage = [UIImage imageNamed:@"apple.png"];
[mView.layer addSublayer:mainLayer];
// start a timet that will fire 20 times per second
[NSTimer scheduledTimerWithTimeInterval:(0.8) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
self.view=mView;
}
return self;
}
我用這個得到那個從頂部動畫到屏幕的底部的圖像的位置。 但我得到了動畫的圖像的x和y的一致值。
任何人都可以幫忙。 感謝U.
當你想要那些座標?在每個循環之後(調用onTimer)? – Ravin 2011-04-16 07:02:51
是的,我想在每個循環之後進行座標。 – Lakshmi 2011-04-16 09:05:50