上拉跳轉介面,仿淘寶
專案中提出這麼個需求,在首頁中上拉,然後直接跳轉到地圖找房介面,想了下,用監聽scrollview加動畫實現了這一效果,上程式碼:
// 監聽scrollview的滑動事件,這裡我設定了上拉距離超過200就跳轉
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"%f",scrollView.contentOffset.y);
if (scrollView.contentOffset.y >= 200) {
[selfpushToMapSearchHouseVC];
}
}
// 跳轉
-(void)pushToMapSearchHouseVC {
// 搞一個動畫
CATransition *trans = [CATransitionanimation];
trans.duration = 1;
trans.type = kCATransitionPush;
trans.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// 設定樣式為從底部向上推出
trans.subtype
[self.navigationController.view.layeraddAnimation:trans forKey:nil];
MapSerachViewController *VC=[[MapSerachViewControlleralloc]init];
VC.type = 3;
[self.navigationControllerpushViewController:VC animated:YES];
}
至此,大功告成,若你的ViewController不是滑動檢視,要想實現這個效果,可以用
-(
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
if (point.y < -200) {
/*
跳轉
*/
}
}
嘗試一下