2012-01-30 42 views

回答

17

一旦你有了點作爲CGPoint您可以撥打:

// Objective-C 
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view 

// C#'s UIView class contains this method: 
PointF ConvertPointToView (PointF point, UIView target); 

上你的UIView。

通過你點在你的意見座標點。而對於視通在

// Objective-C 
[UIWindow keyWindow] 

// C# 
UIWindow.KeyWindow 

這將然後返回一個CGPoint(在C#中的PointF)轉換成窗口座標系!

因此,例如:

// Objective-C 
CGPoint convertedPoint = [myScrollView convertPoint:textField.frame.origin 
              toView:[UIWindow keyWindow]]; 

// C# 
var convertedPoint = myScrollView.ConvertPointToView (
    textField.Frame.Location, UIWindow.KeyWindow); 

希望這有助於:)

2

可能只是我,但難道不這項工作很好?

- (CGRect) convertView:(UIView*)view 
{ 
    CGRect rect = view.frame; 

    while(view.superview) 
    { 
     view = view.superview; 
     rect.origin.x += view.frame.origin.x; 
     rect.origin.y += view.frame.origin.y; 
    } 

    return rect; 

} 
+0

不是,當在某個時候一個視圖是在一個UIScrollView。 – 2013-08-15 14:17:45

相關問題