1

I have problems getting the coordinate convertion from the local view frame to the window right. I have an "Arrow" image that needs to be moved relative to a UIButton on the page when tapped and when the page loads.

The Arrow image (intense name "interfaceApertureSelectionArrow") is initialized in the "didLoadView" method

- (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];  
...
}  

For reacting on the button tap I implemented a Button Action, doing the coordinate conversion using the "convertPoint" method. In this case the conversion and arrow placement works works just right (!)

-(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)];
}

... so far so good. Now here's the problem. When I try to position the arrow next to the "darkButton" coordinates in the viewDidLoad method to show the selection not only on tapping the button but also on loading the view initially the positioning does not work! Here's what I tried.

Added to the viewDidLoad method:

 ...   
 CGPoint superPoint = [darkButton.superview convertPoint:darkButton.frame.origin toView:nil];
    [self moveImageView:interfaceApertureSelectionLineArrow toCGPoint:CGPointMake(superPoint.x, superPoint.y)];        
 ...

The move function that animates the movement of the arrow's UIImageView (in case this is relevant as well)

-(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];
}

Checking the CGPoint value before and after the conversion of the darkButton's CGPoint coordinates shows me that is does not change. How come? (as it did work in the "setAttributeAperture" button method)

4

0 回答 0