本文介绍了移动图像从左至右和右用于iPhone到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve x:(CGFloat)x y:(CGFloat)y
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageToMove =
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]];
imageToMove.frame = CGRectMake(10, 10, 20, 20);
[self.view addSubview:imageToMove];
// Move the image
[self moveImage:imageToMove duration:3.0
curve:UIViewAnimationCurveLinear x:50.0 y:50.0];
}
我已经试过这one.It在从左right.But我需要将图像一次性工作正常,从左右反复离开了。
I have tried this one.It works fine at one time from left to right.But i need to move the image from left and right to left repeatedly.
先谢谢了。
推荐答案
Ÿ不创建的NSTimer反复调用函数,每5秒(其中5是时间REQD从从左向右移动),然后这个函数会检查
y dont you create a NSTimer that repeatedly calls the function every 5 secs(where 5 is the time reqd to move from left to right) and then this function will check.
if(image.origin.x< 0 )
//move image to right
else if(image.origin.x > 320)
// move image to left.
无论用户的 的NSTimer
或你的移动功能调用 [自performSelector:]
Either user NSTimer
or in your move function call a [self performSelector:];
这篇关于移动图像从左至右和右用于iPhone到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!