ary*_*axt 33 iphone objective-c uiwindow ios
我有一个UIView,它在点击后显示一个弹出窗口.弹出窗口需要添加到主UIWindow以确保它在其他所有内容之上.
我希望这个弹出窗口的位置与我的UIView相关,所以我需要知道我的UIView在窗口中的相对位置.
问题:当UIView不是直接在UIWindow中时(如果在我的viewController视图中),如何在UIWindow中找到UIView的位置?
Mag*_*ave 65
使用可以使用UIView方法covertRect:toView转换为新的坐标空间.我做了一些非常相似的事:
// Convert the co-ordinates of the view into the window co-ordinate space
CGRect newFrame = [self convertRect:self.bounds toView:nil];
// Add this view to the main window
[self.window addSubview:self];
self.frame = newFrame;
Run Code Online (Sandbox Code Playgroud)
在我的示例中,self是一个从superView中删除并添加到窗口顶部的视图.toView中的nil参数:表示使用窗口而不是特定视图.
希望这可以帮助,
戴夫
Yun*_*hel 12
您可以要求您为您.superview
转换origin
CGPoint originGlobal = [myView.superview convertPoint:myView.frame.origin
toView:nil];
Run Code Online (Sandbox Code Playgroud)
UIView的convertPoint:toView:不工作吗?所以:
CGPoint windowPoint = [myView convertPoint:myView.bounds.origin toView:myWindow];
Run Code Online (Sandbox Code Playgroud)
我需要在Xamarin.iOS中这样做
对于那里寻找解决方案的人来说,最终对我有用的是:
CGRect globalRect = smallView.ConvertRectToView(smallView.Bounds, rootView);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
41260 次 |
最近记录: |