【问题标题】:When updating a UIImageView image file, other UIImageView gets its position reset to center更新 UIImageView 图像文件时,其他 UIImageView 将其位置重置为中心
【发布时间】:2013-01-11 20:01:32
【问题描述】:

我一直在尝试几乎同时更新两个 UIImageView 元素。一个应该改变它的位置(image01),另一个应该改变它的图像文件(image02)。

这里的问题是,当我更改image02的图像文件时,image01的位置数据被重置为中心(即元素的原点)。

我完全在这里。你们中有人对造成这种情况的原因有任何想法吗?

代码如下:

- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];

    // Setting crosshair new position
    [self setCrossHairPosition:point];
    // Getting camera preview, and discovering pixel color at touch location
    // I also set colorName here
    [self captureNow:touch];

    // Getting file and inserting it in the UIImageView
    fileName = [NSString stringWithFormat:@"%@.png", colorName];
     _colorADDPreview.image = [UIImage imageNamed:fileName];
}

- (void) setCrossHairPosition:(CGPoint)point {
    CGRect crossHairRect = _crossHair.frame;
    crossHairRect.origin.x = point.x - (crossHairRect.size.width/2);
    crossHairRect.origin.y = point.y - (crossHairRect.size.height/2);
    _crossHair.frame = crossHairRect;
}

【问题讨论】:

  • 抱歉,代码已插入 =]

标签: objective-c cocoa-touch uiimage


【解决方案1】:

我意识到问题出在屏幕的重绘上。

因此,我没有通过界面构建​​器插入元素,而是以编程方式插入它并跟踪它在变量中的位置 =]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    • 2013-03-14
    相关资源
    最近更新 更多