【问题标题】:Obtain location coordinates from UIButton从 UIButton 获取位置坐标
【发布时间】:2011-11-28 20:16:54
【问题描述】:

我正在尝试获取主视图控制器的子视图中的 UIButton 的坐标。我可以使用下面的代码将它们相对于子视图返回,但是如何返回与主视图控制器相关的 UIButton 位置?

ScrollingAppDelegate *appDelegate = (ScrollingAppDelegate *)[[UIApplication sharedApplication] delegate]; CGPoint canXY = appDelegate.globalcanButtonReference.frame.origin; NSLog(@"%f ​​%f",canXY.x,canXY.y);

【问题讨论】:

    标签: iphone objective-c ios cocoa-touch uiviewcontroller


    【解决方案1】:

    假设您没有对所有视图的引用,这应该可行:

    CGPoint buttonOrigin = appDelegate.globalcanButtonReference.frame.origin;
    CGPoint superViewOrigin = appDelegate.globalcanButtonReference.superview.frame.origin;
    CGPoint pointInMainViewController = CGPointMake(buttonOrigin.x + superViewOrigin.x, buttonOrigin.y + superViewOrigin.y);
    

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      相关资源
      最近更新 更多