Home  >  Q&A  >  body text

ios - UIView 如何判断自己不在用户的可视范围呢?

要求:方案简单易行,用户无感知(不能占用过高的 CPU)
背景:需要封装一个视图控件,该控件需要根据陀螺仪进行频繁的重绘。

目前需要考虑以下情况:

PHPzPHPz2716 days ago673

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-18 09:57:01

    alpha, hidden——You can know these two UIViews by getting their own properties
    UIScrollView subview——You can get the frame of UIView relative to the screen through [scrollView convertRect:self.frame toView:[UIApplication sharedApplication].keyWindow];, and you can also judge whether it is within the view range through specific data
    Make a phone call or enter the background - by implementing the corresponding proxy method in appdelegate, a notification will be sent after the proxy method is executed, so that UIView can receive the notification and also know that it is blocked by other views - you can control this thing yourself, write your own app , you will definitely know when the obstruction will occur

    reply
    0
  • 阿神

    阿神2017-04-18 09:57:01

    /* Return true if rect2' is contained in rect1', false otherwise. `rect2'
    is contained in rect1' if the union of rect1' and `rect2' is equal to
    `rect1'. */

    CG_EXTERN bool CGRectContainsRect(CGRect rect1, CGRect rect2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:57:01

    Didn’t you list them all?

    reply
    0
  • Cancelreply