优艾设计网

在UISCrollview拖动上面的view,不能实现自动布局?

case UIGestureRecognizerStateChanged:{//跟随手指移动的截图 offsetXoflistView = listViewCentreInWindow.x - inWindow.x;snapView.center = CGPointMake(inWindow.x+offsetXoflistView, inWindow.y+offsetYoflistView); //判断截图横向滚动的边界 if (CGRectGetMaxX(snapView.frame)<=ScreenWidth) {rollBeginMaxX = ScreenWidth; } if (CGRectGetMinX(snapView.frame)>=0) {rollBeginMinX = 0;} //当截图超过屏幕 if (CGRectGetMaxX(snapView.frame)>rollBeginMaxX) { // 起始点 NSInteger startIndex = [self StartIndexOfView:superOFHeadView singArray:self.arrlists]; CGPoint pointOfsnapView = [self.window convertPoint:snapView.center toView:self];// 目标点 NSInteger endIndexPoint = [self indexOfPoint:pointOfsnapView withUiview:snapView singArray:self.arrlists]; NSLog(@"%f,%f",snapView.center.x,snapView.center.y); NSLog(@"开始下标:::%ld",(long)startIndex); NSLog(@"结束下标:::%ld",(long)endIndexPoint); ////向后拖动 if (startIndex < endIndexPoint && endIndexPoint < _arrlists.count) {UIView *endView = self.arrlists[endIndexPoint];// 把截图转化成scrollView上的坐标 CGPoint snapViewInscrollView = [self convertPoint:snapView.center toView:self]; snapViewInscrollView.x = endView.yyCenterX;for (NSInteger j = startIndex; j < endIndexPoint; j++) {UIView *singView1 = self.arrlists[j]; UIView *singView2 = self.arrlists[j+1];[UIView animateWithDuration:0.5 animations:^{singView2.yyCenterX = singView1.yyCenterX;}]; } [self.arrlists removeObject:superOFHeadView]; [self.arrlists insertObject:snapView atIndex:endIndexPoint];} if (!link) { // 初始化一个CADisplayLink 一秒调用60次 link = [CADisplayLink displayLinkWithTarget:self selector:@selector(adjustOffSet)]; [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; //根据截图的范围与边界的关系,调整滚动的快慢参数 if ((CGRectGetMaxX(snapView.frame) - rollBeginMaxX)/5 < 1) { _incrementHeadView = 1; } else if((CGRectGetMaxX(snapView.frame) - rollBeginMaxX)/5 > 20) { _incrementHeadView = 5; } else { _incrementHeadView = (CGRectGetMaxX(snapView.frame) - rollBeginMaxX)/5; }}} else if (CGRectGetMinX(snapView.frame) < rollBeginMinX) {//向左滚动 if (!link) { link = [CADisplayLink displayLinkWithTarget:self selector:@selector(minusContentOffset)]; [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; }if (-(CGRectGetMinX(snapView.fram优艾设计网_PS论坛e) - rollBeginMinX)/5 < 1) { _increment = 1; } else if(-(CGRectGetMinX(snapView.frame) - rollBeginMinX)/5 > 20) { _increment = 5; } else { _increment = -(CGRectGetMinX(snapView.frame) - rollBeginMinX)/5; } } else { //截图大小范围没有超过左右边界时,滚动停止 [link invalidate]; link = nil; [link invalidate]; link = nil; }


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜