[英]Move a UIImageView in y axis
I am working on a app and i want to move a UIImage in the Y axis only, not in Xaxis, here's what i did till now 我正在开发应用程序,我只想在Y轴上移动UIImage,而不要在Xaxis上移动,这是我到目前为止所做的
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { stretchPoint = [[touches anyObject]locationInView:self.view]; arrowImage.center = stretchPoint; }
The above code is moving the arrowImage in both the axis, stretchPoint is an instance of CGPoint, My app is in portrait mode, can anyone give me a basic idea to how to do this, as the arrowImage is a instance of UIImageView. 上面的代码在两个轴上都移动了arrowImage,stretchPoint是CGPoint的一个实例,我的应用程序处于纵向模式,任何人都可以给我一个基本的想法,因为arrowImage是UIImageView的一个实例。
Subclass the UIImage and implement the following code 子类化UIImage并实现以下代码
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:[self superview]];
CGPoint newCenter = CGPointMake(self.center.x, currentPoint.y);
self.center = newCenter;
}
this should work fine: 这应该工作正常:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.x = arrowImage.center.x;
arrowImage.center = currentPoint;
}
I am not sure as have not tested,but you can implement something like this : 我不确定还没有测试过,但是您可以执行以下操作:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y = 20;
}
Something like: 就像是:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
stretchPoint = [[touches anyObject] locationInView:self.view];
arrowImage.frame = CGPointMake(arrowImage.origin.x,
stretchPoint.y,
arrowImage.size.width,
arrowImage.size.height);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.