我是新的objective-c。我創建UIScrollView
對象,在我看來,添加此代碼:滾動時如何在UIScrollView中移動一個方向
height = self.view.frame.size.height;
width = self.view.frame.size.width;
scrollbar = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
scrollbar.delegate = self;
scrollbar.backgroundColor = [UIColor whiteColor];
scrollbar.maximumZoomScale = 1.0;
scrollbar.minimumZoomScale = 1.0;
scrollbar.clipsToBounds = YES;
scrollbar.showsHorizontalScrollIndicator = YES;
scrollbar.pagingEnabled = YES;
[scrollbar setContentSize:CGSizeMake(width*4, height*4)];
[self.view addSubview:scrollbar];
for (int i = 1; i <= 4; i++) {
first = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
first.view.frame = CGRectMake((i-1)*width, 0, width, height*4);
[scrollbar addSubview:first.view];
switch (i) {
ase 1:
first.view.backgroundColor = [UIColor blueColor];
break;
case 2:
first.view.backgroundColor = [UIColor redColor];
break;
case 3:
first.view.backgroundColor = [UIColor greenColor];
break;
case 4:
first.view.backgroundColor = [UIColor grayColor];
break;
default:
break;
}
}
在我的代碼
我加4觀點在我的滾動型有不同的顏色,現在我的滾動型滾動時,我想檢測DX & DY(DX:行駛距離on Axis.x & dy:在Axis.y上的行駛距離),並檢查這兩個變量和時間:
Notic:我希望當任何人觸摸ScrollView並在Axis(x或y)上移動觸摸或觸摸Both軸(x和y)檢查此:
if(dx> dy)disable水平滾動和垂直移動! 否則在水平方向移動並禁用垂直滾動!
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect visibleRect = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.contentOffset.x + scrollView.bounds.size.width, scrollView.contentOffset.y + scrollView.bounds.size.height);
NSLog(@"%f,%f",visibleRect.origin.x,visibleRect.origin.y);
/*NSLog(@"x : %f",scrollView.contentOffset.x);
NSLog(@"y : %f",scrollView.contentOffset.y);*/
if (fabsf(scrollView.contentOffset.x) > fabsf(scrollView.contentOffset.y)) {
NSLog(@"Vertical Side");
}
else {
NSLog(@"Horizontal Side");
}
}
請指導我的傢伙。我不能禁用一邊和移動另一邊!謝謝
謝謝我的老兄,這是我的回答! – user3797431