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