我有一个uiview,我想在向下滚动并向上滚动桌面时隐藏和显示,
这是我到目前为止所做的:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].y > 0) {
NSLog(@"moving up");
} else {
scrollingUp = false;
NSLog(@"moving down");
[self pushUpsearchView];
}
}
pushUpsearchView方法:
-(void)pushUpsearchView{
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.mysearchView.frame;
frame.origin.x = self.mysearchView.frame.origin.x;
frame.origin.y = 100;
self.mysearchView.frame = frame;
self.mysearchView.frame = frame;
} completion:^(BOOL finished){
NSLog(@"Finished animating!");
}];
}
但这就是我最终的结果:
但是,当我从[self pushUpsearchView]
方法移除scrollViewWillBeginDragging
并将其放入我的viewdidload
方法时,它可以正常运行而不会重复它只是更改其位置