我會用一個覆蓋UIScrollView
爲紅拖動部分。並且只允許垂直滾動並將pagingEnabled
設置爲NO
。並將它的delegate
設置爲視圖控制器。
然後,你可以爲每個頁面500step您的自定義分頁通過kCellHeigth設置對應於500steps在圖像的像素數如下:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
CGFloat kMaxIndex = 30; //=15000/500
CGFloat targetY = scrollView.contentOffset.y + velocity.y * 60.0;
CGFloat targetIndex = round(targetY/(kCellHeigth + kCellSpacing));
if (targetIndex < 0)
targetIndex = 0;
if (targetIndex > kMaxIndex)
targetIndex = kMaxIndex;
targetContentOffset->y = targetIndex * (kCellHeigth + kCellSpacing);
}
- 新的解決方案看你的代碼後 -
我看到對於iPhone5(寬度= 320),相鄰圓圈之間的半徑增量約爲20個點。而這個空間相當於2500步。
So 1 point = 125 steps
由於您想要500步增量,它對應於iPhone5/5s屏幕中的4個點。也許當用戶觸摸結束,你可以嘗試將導航儀捕捉到最近的4點網格:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__FUNCTION__);
UITouch *touch = [touches anyObject];
touchPoint = [touch locationInView:_navView];
CGPoint newCenter = CGPointMake(_navView.center.x, _navView.center.y + (touchPoint.y - touchStart.y));
CGFloat yDelta = newCenter.y - _navMinPoint.y;
int yDeltaMultiple = yDelta/4;
int newYDelta = yDeltaMultiple * 4;
newCenter.y = newYDelta;
_navView.center = newCenter;
_labelSteps.center = [self setStepsLabelfromNavView];
}
我沒有在Xcode中寫這些所以有可能是拼寫錯誤/錯誤。如果這適用於iPhone 5/5s,那麼我們需要將4 points
更改爲變量。
你可以使用從最內圈中心拖動視圖的距離來計算步驟 –
@VijayMasiwal你可以看看我的代碼我認爲我接近解決方案但不知道我的錯誤是什麼? –