1

ローカル ビュー フレームからウィンドウへの座標変換に問題があります。タップしたときとページが読み込まれたときに、ページ上の UIButton に対して相対的に移動する必要がある「矢印」画像があります。

矢印イメージ (名前は「interfaceApertureSelectionArrow」) は「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 メソッドの「darkButton」座標の横に矢印を配置して、ボタンをタップするだけでなく、最初にビューをロードするときにも選択を表示しようとすると、配置が機能しません! これが私が試したものです。

viewDidLoad メソッドに追加:

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

矢印の UIImageView の動きをアニメーション化する move 関数 (これも関連する場合)

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

darkButton の CGPoint 座標の変換の前後で CGPoint 値を確認すると、変化していないことがわかります。どうして?(「setAttributeAperture」ボタンメソッドで機能したように)

4

0 に答える 0