2014-07-18 73 views
0

如何確定控件是否位於iOS的顯示區域內?如何確定控件是否位於顯示區域

例如

有一個UILabel,它會從屏幕右側滑到左邊,直到它從屏幕上滑到邊界的左邊,我如何確定它是否已經滑出邊界?


我使用動畫塊模型。當動畫完成時,我們可以確定Label已經超過了0;

現在我想刪除標籤。

例如

[UIView animateWithDuration:5.5 
         delay:0.1 
        options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat 
       animations:^ 
{ 

    [UIView setAnimationRepeatCount:3]; 

    CGRect lsframe = labelShow.frame; 
    lsframe.origin.x = 0; 
    lsframe.origin.y = dphv.mImgContent.frame.origin.y; 
    lsframe.size.width = 8; 
    lsframe.size.height = imgH; 


    CGRect frame = labelShow.frame; 
    frame.origin.x = 600; 
    labelShow.frame = frame; 

    frame = labelShow.frame; 
    frame.origin.x = -180; 
    labelShow.frame = frame; 

} 
completion:^(BOOL finished) 
{ 
    NSLog(@"animation finished"); 

    labelShow = nil; //but this line has error, how can I do this; 
}]; 

我用這個例子,但這個例子有一個非常嚴重的問題,導致內存了,甚至超過100m,但我不知道如何解決改革。這是網址:https://github.com/yinkou/OBaconView

回答

0

檢查標籤的frame.origin.x param作爲其移動。假設父視圖的x參數與屏幕的x = 0對齊,那麼標籤的x變爲小於0,則標籤不在視圖中。

1

該標籤有一個frame屬性,可讓您知道它的超級視圖內的位置。超級看法有一個bounds屬性,讓你知道內容可以在哪裏。使用這些屬性,您可以檢查標籤的框架是否在超級視圖的範圍內。

0

您也可以使用方法-convertRect:toView:來查找視圖落入視圖控制器視圖的位置。使用方法返回的矩形,檢查是否有任何角落落在主視圖中。

相關問題