我有一个以横向模式创建的视图(旋转后很长时间等).
在这个视图中,我想找到一个相对于主窗口的点.
以下代码在纵向模式下工作,但在landscappe中,它仍然返回值,就像它是纵向的一样.
CGPoint ptRelativeToWindow = [self convertPoint:self.bounds.origin toView:nil];
Run Code Online (Sandbox Code Playgroud)
解决了
这解决了问题并提供了正确的坐标:
[self convertPoint:self.bounds.origin toView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但我无法找到答案......
我有一个UIScrollView和许多UIButtons.当我按下按钮时,我想知道按钮的屏幕位置.如果我使用button.frame,它会给我在UIScrollView中的位置,这是正常的.
如何找到相对于按下按钮屏幕的x和y?
提前致谢.
我知道convertRect:toRect这里的关键,但我不知道如何称呼它.我有我的单元格的子视图,我希望它在应用程序的整个窗口中的位置.
当我在其目标操作方法中点击此按钮(子视图)时,我需要知道这一点.我convertRect:toRect想,为了获得正确的坐标,我需要在单元格上调用函数,但在这种方法中,我没有引用单元格本身.
我是否爬上超级视图层次结构?这看起来很糟糕,因为我不完全确定我会得到什么,因为它嵌入在单元格的contentView中,而且Apple通过私人子视图和诸如此类的东西做了古怪的事情.
码:
@IBAction buttonPressed(sender: UIButton) {
// This button got the callback that it was pressed. It's in a cell. I need to convert its rect to that of the window here. I need the coordinate system it's calculated from (the cell) which I'm not sure of how to easily do in a target action callback.
}
Run Code Online (Sandbox Code Playgroud) 我很高兴看到这个:如何转换子视图的点的答案 ,它在模拟器上对我来说非常适合.
但由于某种原因,它无法在设备上运行......可能是视图位置由设备管理不同 - 或者它只是另一个谜?或者(希望)我写错了,你们可以帮忙...... :)
这是我的路线:
CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
Run Code Online (Sandbox Code Playgroud) 我想在UIScrollView中获取UIButton的位置问题是,当UIButton位于其原始位置或向下滚动时,我得到相同的位置...
我正在使用NSLog打印位置,我得到相同的输出
没有向下滚动我得到...
2014-11-05 19:28:02.564 ... {{260, 163}, {370, 225}}
Run Code Online (Sandbox Code Playgroud)即使我向下滚动,我也得到相同的输出......
2014-11-05 19:28:06.052 ... {{260, 163}, {370, 225}}
Run Code Online (Sandbox Code Playgroud)这是我使用获得的位置代码的UIButton里面的UIScrollView ...
NSLog(@"%@", NSStringFromCGRect(CGRectMake(myButton.frame.origin.x, myButton.frame.origin.y, myScrollDown.frame.size.width, myScrollDown.frame.size.height)));
Run Code Online (Sandbox Code Playgroud)
有一种方法可以在我向下滚动后获得UIButton的实际位置?
还有另一种方法可以在ScrollView中获取UIButton的位置吗?
我已经访问了以下链接,但我还没有解决它.
iPhone - 在整个UIWindow中获取UIView的位置
谢谢你的帮助!
有没有一种简单的方法来获得UIView的绝对点?绝对我的意思是UIView在iPad上相对于1024x768的位置?
我需要一个简单的方法,因为我在UITableView内部的UITutView内部有一个UIButView视图,该视图由一个viewcontroller呈现,该视图控制器是另一个视图控制器的子节点,重复到第五或第六视图控制器.由于这种复杂的设计,我需要UIButton的绝对矩形,所以我可以在"main"viewcontroller上显示一个UIActionSheet.
ios ×4
objective-c ×4
uiview ×3
cocoa-touch ×2
xcode ×2
cgpoint ×1
cgrect ×1
iphone ×1
uibutton ×1
uiscrollview ×1
uitableview ×1