Ios 在屏幕上放置UIImageView,发出UIView坐标转换

Ios 在屏幕上放置UIImageView,发出UIView坐标转换,ios,uiview,coordinates,cgpoint,Ios,Uiview,Coordinates,Cgpoint,我在将坐标从局部视图框架转换到窗口右侧时遇到问题。我有一个箭头图像,当点击和加载页面时,它需要相对于页面上的UIButton移动 箭头图像名称界面PertureSelectionarRow在didLoadView方法中初始化 - (void)viewDidLoad { ... //only initial values here, the image i will be moved using the moveImageView:to: function CGRect apertureSel

我在将坐标从局部视图框架转换到窗口右侧时遇到问题。我有一个箭头图像,当点击和加载页面时,它需要相对于页面上的UIButton移动

箭头图像名称界面PertureSelectionarRow在didLoadView方法中初始化

- (void)viewDidLoad
{ 
...
//only initial values here, the image i will be moved using the moveImageView:to: function 
CGRect apertureSelectorArrowFrame = CGRectMake(300.0f, 125.0f, 30.0f, 30.0f);    
[self addImageView:interfaceApertureSelectionLineArrow withFrame:apertureSelectorArrowFrame];    
interfaceApertureSelectionLineArrow = [[UIImageView alloc] initWithFrame:apertureSelectorArrowFrame];
[interfaceApertureSelectionLineArrow setImage:[UIImage imageNamed:@"InterfaceSelectionLineArrow@2x"]];
interfaceApertureSelectionLineArrow.opaque = YES;
[self.view addSubview:interfaceApertureSelectionLineArrow];  
...
}  
为了对按钮点击做出反应,我实现了一个按钮操作,使用convertPoint方法进行坐标转换。在这种情况下,转换和箭头放置正好工作

-(IBAction)setAttributeAperture:(id)sender{
UIButton *button = (UIButton *)sender;  
CGPoint superPoint = [button.superview convertPoint:button.frame.origin toView:nil];
[self moveImageView:interfaceApertureSelectionLineArrow toCGPoint:CGPointMake(superPoint.x, superPoint.y)];
}
。。。到现在为止,一直都还不错。现在问题来了。当我尝试在viewDidLoad方法中将箭头定位在黑暗按钮坐标旁边以显示选择时,不仅在点击按钮时,而且在最初加载视图时,定位不起作用!这是我试过的

添加到viewDidLoad方法:

 ...   
 CGPoint superPoint = [darkButton.superview convertPoint:darkButton.frame.origin toView:nil];
    [self moveImageView:interfaceApertureSelectionLineArrow toCGPoint:CGPointMake(superPoint.x, superPoint.y)];        
 ...
移动功能,用于在相关情况下为箭头的UIImageView的移动设置动画

-(void)moveImageView:(UIImageView*)thisImageView
       toCGPoint:(CGPoint)thisCGPoint{
[UIView beginAnimations:@"UIImage Move" context:NULL]; 
[UIView setAnimationDuration:1];
CGSize size = thisImageView.frame.size;
thisImageView.frame = CGRectMake(thisCGPoint.x, thisCGPoint.y, size.width, size.height);
[UIView commitAnimations];
}

在转换暗按钮的CGPoint坐标之前和之后检查CGPoint值,这表明它不会改变。怎么会?正如它在SetAttributeApperture按钮方法中所起的作用一样

[UIImage ImageName:@InterfaceSelectionLineArrow@2x]我似乎很怀疑。@2x后缀用于ImageName本身,以使用此处的非视网膜基本名称:InterfaceSelectionLineArrow为当前设备视网膜与非视网膜选择正确分辨率的图像。不确定您为什么直接引用2x版本:这将确保您在非视网膜设备上获得错误的图像。谢谢您的评论。我一定会解决这个问题。然而,这似乎与我的定位/坐标问题无关。