iPhone UIView问题。如何在UIView完全隐藏时收到通知?

时间:2009-09-19 21:43:16

标签: iphone uiview uiscrollview

我有一条UIViews在UIView“窗口”后面水平滑动。只能看到“窗口”范围内的UIViews。随着视图变得隐藏,我希望得到通知,以便我可以使用刚刚隐藏的视图执行某些任务。这样做的最佳方式是什么?

2 个答案:

答案 0 :(得分:2)

在你的UIScrollViewDelegate中:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // left and right bounds of the subview in relation to the scrollview
    CGFloat left = mySubview.frame.origin.x - myScrollView.contentOffset.x;
    CGFloat right = left+mySubview.frame.size.width - myScrollView.contentOffset.x;
    if(right<=0 || left>=myScrollView.frame.size.width){
        // The view is not visible
    }
}

检查子视图的左侧或右侧是否可见。

答案 1 :(得分:1)

为动画添加回调选择器:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:theView cache:NO];
    [UIView setAnimationDidStopSelector:@selector(animationDone)];
    theView.frame = newFrame;
    [UIView commitAnimations];