在UISCrollview拖动上面的view,不能实现自动布局 财富值67

2016-10-14 08:16发布

        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.frame) - 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条回答