IOS开发——页面控件拖动
来源:互联网 发布:递归算法计算树的度 编辑:程序博客网 时间:2024/05/22 15:58
IOS开发——页面控件拖动
Demo下载地址:http://download.csdn.net/detail/u012881779/8442427
图例:
Demo下载地址:http://download.csdn.net/detail/u012881779/8442427
#import "HomeViewController.h"#import "AppDelegate.h"@interface HomeViewController ()<UIScrollViewDelegate>@property (nonatomic) float gEntryHeight;@property (nonatomic) BOOL gLongPress; //长按@property (nonatomic) float gTitleH; //导航栏高度@property (nonatomic) float gStatusH; //状态栏高度@property (nonatomic) NSInteger gIndexB; //手势开始@property (nonatomic) NSInteger gIndexBM; //手势开始@property (nonatomic) NSInteger gIndexM; //手势拖动@property (nonatomic) NSInteger gIndexE; //手势结束@property (nonatomic) BOOL gMoveSVYes; //是否移动SV@property (strong, nonatomic) UIScrollView *gBootSV; //底层适配SV@property (strong, nonatomic) UIPanGestureRecognizer *gPanRecognizer;//拖动手势@property (strong, nonatomic) NSMutableArray *gQuickArr; //板块快捷入口@property (strong, nonatomic) NSMutableArray *gHomeEnterArr; //主页入口@property (strong, nonatomic) UIView *gQuickEntryV; //快捷入口V@property (strong, nonatomic) UIView *gMoveV; //拖动的View@property (strong, nonatomic) NSMutableArray *gEntryMarrPoint;//入口中心坐标@property (strong, nonatomic) NSMutableArray *gPanMArr; //拖动手势Arr@end- (void)viewDidLoad{ [super viewDidLoad]; AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; self.view.bounds = app.window.screen.bounds; if([[UIDevice currentDevice].systemVersion floatValue] >= 7.0){ _gTitleH = 64; _gStatusH = 20; }else{ _gTitleH = 44; _gStatusH = 0; } //标题栏 [self cTitleBar]; UIView *tempVi = (UIView *)[self.view viewWithTag:5556]; self.gBootSV = [[UIScrollView alloc] init]; if([[UIDevice currentDevice].systemVersion floatValue] >= 7.0){ [self.gBootSV setFrame:CGRectMake(0, tempVi.frame.origin.y+tempVi.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-self.gTitleH)]; }else{ [self.gBootSV setFrame:CGRectMake(0, tempVi.frame.origin.y+tempVi.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-self.gTitleH-20)]; } [self.gBootSV setShowsVerticalScrollIndicator:NO]; self.gBootSV.tag = 5454; [self.gBootSV setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:self.gBootSV]; _gLongPress = NO; //首页快捷入口 [self cQuickEntry]; }//标题栏-(void)cTitleBar{ //底图背景 UIView *baseV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, _gTitleH)]; baseV.tag = 5556; [self.view addSubview:baseV]; [baseV setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"导航栏.png"]]]; //栏目入口 UIButton *columnBut = [[UIButton alloc] initWithFrame:CGRectMake(0, _gStatusH+(_gTitleH-_gStatusH-40)/2, 36, 40)]; [columnBut setImage:[UIImage imageNamed:@"加号.png"] forState:UIControlStateNormal]; [columnBut addTarget:self action:@selector(cPopColumnEntry) forControlEvents:UIControlEventTouchUpInside]; columnBut.selected = YES; columnBut.tag = 1000; [baseV addSubview:columnBut]; //用户中心入口 UIButton *userBut = [[UIButton alloc] initWithFrame:CGRectMake(320-41, _gStatusH+(_gTitleH-_gStatusH-40)/2, 41, 40)]; [userBut setImage:[UIImage imageNamed:@"个人中心.png"] forState:UIControlStateNormal]; [userBut addTarget:self action:@selector(cPopUserCenter) forControlEvents:UIControlEventTouchUpInside]; userBut.selected = YES; userBut.tag = 1001; [baseV addSubview:userBut]; //标题栏 UILabel *titleV = [[UILabel alloc] initWithFrame:CGRectMake(_gTitleH, _gStatusH, 320-2*_gTitleH, _gTitleH-_gStatusH)]; [titleV setText:@"测试项目"]; [titleV setBackgroundColor:[UIColor clearColor]]; [titleV setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]]; [titleV setTextColor:[UIColor whiteColor] ]; [titleV setTextAlignment:NSTextAlignmentCenter]; [baseV addSubview:titleV];}//首页快捷入口-(void)cQuickEntry{ //首页入口名 获取 [self cEntryName]; float cancel_h = 22; //小叉 高度 float quickEntryH = self.view.frame.size.width/3;//快捷入口宽度 if(!_gQuickEntryV){ _gQuickEntryV = [[UIView alloc] initWithFrame:CGRectMake(0, _gEntryHeight, _gBootSV.frame.size.width, 2000)]; [_gBootSV addSubview:_gQuickEntryV ]; } NSArray *subVarr = [_gQuickEntryV subviews]; for(int k = 0; k < [subVarr count]; k ++){ UIView *tempV = (UIView *)[subVarr objectAtIndex:k]; [tempV removeFromSuperview]; tempV = nil; } //存储入口View if(!_gPanMArr){ _gPanMArr = [[NSMutableArray alloc] init]; } [_gPanMArr removeAllObjects]; //各入口中心坐标 if(!_gEntryMarrPoint){ _gEntryMarrPoint = [[NSMutableArray alloc] init]; } [_gEntryMarrPoint removeAllObjects]; //点击事件 UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cTapRecognizer:)]; [_gBootSV addGestureRecognizer:tapRec]; //有多少个快捷入口 NSInteger count = [_gQuickArr count]; for(int i = 0; i < (count-1)/3+1; i ++){ int tempJ = 3; if(i == (count-1)/3){ if(count%3 !=0){ tempJ = count%3; } } if(count < 3){ tempJ = count; } for(int j = 0; j < tempJ; j ++){ //数据 int index = i*3+j; NSDictionary * dict = (NSDictionary *)[_gQuickArr objectAtIndex:index]; //入口名 NSString *strName = [dict objectForKey:@"c_name"]; //快捷入口 UIView *entryV = [[UIView alloc ] initWithFrame:CGRectMake(quickEntryH*j, quickEntryH*i, quickEntryH, quickEntryH)]; entryV.tag = 5000+index; [_gPanMArr addObject:entryV]; [_gQuickEntryV addSubview:entryV]; [_gEntryMarrPoint addObject:[NSValue valueWithCGPoint:entryV.center]]; //右分隔 CGRect rightFrame = entryV.bounds; rightFrame.origin.x = rightFrame.size.width-1; rightFrame.size.width = 1; UIView *rightV = [[UIView alloc] init]; [rightV setFrame:rightFrame]; [rightV setBackgroundColor:[UIColor grayColor]]; [entryV addSubview:rightV]; //下分隔 CGRect downFrame = entryV.bounds; downFrame.origin.y = downFrame.size.height-1; downFrame.size.height = 1; UIView *downV = [[UIView alloc] init]; [downV setFrame:downFrame]; [downV setBackgroundColor:[UIColor grayColor]]; [entryV addSubview:downV]; //长按手势 UILongPressGestureRecognizer *longR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(cLongGestureEntryButCancel:)]; [entryV addGestureRecognizer:longR]; if(_gLongPress){ //添加拖动手势 [self cBugPanCesture]; } //是否存在删除按钮 BOOL hiddenCancel = [[dict objectForKey:@"isdelete"] boolValue]; if(hiddenCancel){ //删除快捷键 UIButton *cancelBut = [[UIButton alloc] initWithFrame:CGRectMake(entryV.bounds.size.width-cancel_h-3, 3, cancel_h, cancel_h)]; [cancelBut setImage:[UIImage imageNamed:@"删除.png"] forState:UIControlStateNormal]; [cancelBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [cancelBut.titleLabel setTextAlignment:NSTextAlignmentCenter]; [cancelBut setHidden:!_gLongPress]; cancelBut.tag =4000; [cancelBut addTarget:self action:@selector(cCancelEntry:) forControlEvents:UIControlEventTouchUpInside]; [entryV addSubview:cancelBut]; } //Button圆环 UIButton *entryRoundBut = [[UIButton alloc] initWithFrame:CGRectMake(CGFLOAT_MAX, CGFLOAT_MAX, 70, 70)]; [entryRoundBut setCenter:CGPointMake(quickEntryH/2.0, quickEntryH/2.0-8)]; [entryRoundBut setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"圆环.png"]]]; [entryV addSubview:entryRoundBut]; //Button图标 UIButton *entryBut = [[UIButton alloc] initWithFrame:CGRectMake(CGFLOAT_MAX, CGFLOAT_MAX, 58, 58)]; [entryBut setCenter:CGPointMake(quickEntryH/2.0, quickEntryH/2.0-8)]; entryBut.tag =2000; [entryBut addTarget:self action:@selector(cQuickAction:) forControlEvents:UIControlEventTouchUpInside]; [entryBut.layer setMasksToBounds:YES]; [entryBut.layer setCornerRadius:58/2.0]; [entryV addSubview:entryBut]; //添加图标 UIImage *img; NSURL *temurl = [NSURL URLWithString:[dict objectForKey:@"ar_url"]]; if(![temurl isEqual:@""] && temurl != nil){ NSData *tempdata = [NSData dataWithContentsOfURL:temurl]; img = [UIImage imageWithData:tempdata]; }else{ NSString *strPath = [[NSBundle mainBundle] pathForResource:strName ofType:@"png"]; UIImage *theImg = [UIImage imageWithContentsOfFile:strPath]; if(theImg){ img = theImg; } } //没img 选择默认图片 if(img){ [entryBut setImage:img forState:UIControlStateNormal]; }else{ [entryBut setImage:[UIImage imageNamed:@"默认.png"] forState:UIControlStateNormal]; } //Button名称 float txt_h = 20; UIButton *entryTitle = [[UIButton alloc] initWithFrame:CGRectMake(0, entryV.bounds.size.height-txt_h-5, entryV.bounds.size.width, txt_h)]; [entryV addSubview:entryTitle]; [entryTitle setTitle:[NSString stringWithFormat:@"%@",strName] forState:UIControlStateNormal]; [entryTitle.titleLabel setTextAlignment:NSTextAlignmentCenter]; [entryTitle.titleLabel setFont:[UIFont systemFontOfSize:15]]; if([entryTitle.titleLabel.text length] > 6){ NSInteger fontsiz = 15 - ([entryTitle.titleLabel.text length] - 6); [entryTitle.titleLabel setFont:[UIFont systemFontOfSize:fontsiz]]; } entryTitle.tag =3000+index; [entryTitle setTitleColor:[UIColor blackColor] forState:UIControlStateNormal] ; [entryTitle addTarget:self action:@selector(cQuickAction:) forControlEvents:UIControlEventTouchUpInside]; } } //SV自适应高度 [self cChangeEntryVHeight];}//SV自适应高度-(void)cChangeEntryVHeight{ //_gQuickEntryV的最低高度 float lowHei = self.view.frame.size.height - _gBootSV.frame.origin.y - _gQuickEntryV.frame.origin.y; CGRect theQuickFrame = _gQuickEntryV.frame; theQuickFrame.size.height = lowHei; [_gQuickEntryV setFrame:theQuickFrame]; if(_gPanMArr){ UIView *lastView = (UIView *)[_gPanMArr lastObject]; if(lastView){ float hei = lastView.frame.origin.y + lastView.frame.size.height; if(hei > lowHei){ theQuickFrame.size.height = hei ; [_gQuickEntryV setFrame:theQuickFrame]; } } } [UIView animateWithDuration:0.5 animations:^{ [_gBootSV setContentSize:CGSizeMake(self.view.frame.size.width, _gQuickEntryV.frame.origin.y + _gQuickEntryV.frame.size.height + 5)]; } completion:^(BOOL finished){}];}//点击事件-(void)cTapRecognizer:(UIGestureRecognizer *)recognizer{ if(_gLongPress){ [self cLongGestureEntryBut:nil]; }else{ }}//拖动手势-(void)cPanGesture:(UIPanGestureRecognizer *)recognizer{ //是否长按,处于编辑状态 if(_gLongPress){ UIView *tempV = recognizer.view; CGPoint point = [recognizer translationInView:tempV]; CGPoint tempPoin = tempV.center; tempPoin.x = tempPoin.x + point.x; tempPoin.y = tempPoin.y + point.y; //拖动范围 float the_h = _gQuickEntryV.bounds.size.height; float the_w = _gQuickEntryV.bounds.size.width/3; if(tempPoin.x >= the_w/2 && tempPoin.y >= the_w/2 && tempPoin.x <= (_gQuickEntryV.bounds.size.width-the_w/2) && tempPoin.y <= the_h-the_w/2){ [tempV setCenter:tempPoin]; } [recognizer setTranslation:CGPointMake(0, 0) inView:tempV]; //手势开 CGPoint bPoint; if (recognizer.state == UIGestureRecognizerStateBegan) { _gMoveSVYes = YES; bPoint = recognizer.view.center; _gMoveV = recognizer.view; //使当前拖动Button添加到View的最上层 [_gQuickEntryV addSubview:_gMoveV]; [_gMoveV setAlpha:0.5]; int intx = bPoint.x/the_w; int inty = bPoint.y/the_w; _gIndexB = inty*3 + intx; _gIndexBM = _gIndexB ; } //手势进行 CGPoint mPoint ; if (recognizer.state == UIGestureRecognizerStateChanged) { mPoint = recognizer.view.center; int intx = mPoint.x/the_w; int inty = mPoint.y/the_w; _gIndexM = inty*3 + intx; if(_gIndexM > [_gQuickArr count]-1){ _gIndexM = [_gQuickArr count]-1; UIView *theView = (UIView *)[self.view viewWithTag:5000+_gIndexM]; mPoint = theView.center; } //被拖动V if(_gIndexB < _gIndexM){ //往后方拖 [UIView animateWithDuration:0.2 animations:^{ for(int m = _gIndexB+1;m < _gIndexM+1; m ++){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m-1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m-1; } } completion:^(BOOL finished){}]; CGPoint heiPoint = _gBootSV.contentOffset; float hei_wh = _gBootSV.bounds.size.width/3; float allHei = _gBootSV.contentSize.height; float curHei = _gQuickEntryV.frame.origin.y+mPoint.y; float hei_y = curHei - heiPoint.y; if(hei_y > _gBootSV.bounds.size.height-hei_wh){ heiPoint.y = heiPoint.y + hei_wh; if(heiPoint.y < (allHei-_gBootSV.bounds.size.height)){ CGRect tempFrame = tempV.frame; tempFrame.origin.y = tempFrame.origin.y + hei_wh; [self performSelector:@selector(cAfterMove) withObject:self afterDelay:0.5]; if(mPoint.y <_gQuickEntryV.bounds.size.height-hei_wh*2){ [self performSelector:@selector(cAfterMoveView) withObject:self afterDelay:0.5]; } }else{ heiPoint.y = (allHei-_gBootSV.bounds.size.height); [UIView animateWithDuration:0.2 animations:^{ [_gBootSV setContentOffset:heiPoint]; } completion:^(BOOL finished){}]; } } }else if(_gIndexB > _gIndexM){ //往前方拖 [UIView animateWithDuration:0.2 animations:^{ for(int m = _gIndexB-1;m > _gIndexM-1; m --){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m+1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m+1; } } completion:^(BOOL finished){}]; CGPoint heiPoint = _gBootSV.contentOffset; float hei_wh = _gBootSV.bounds.size.width/3; float curHei = _gQuickEntryV.frame.origin.y+mPoint.y; float hei_y = curHei - heiPoint.y; if(hei_y < hei_wh){//屏幕中坐标 heiPoint.y = heiPoint.y - hei_wh; if(heiPoint.y > hei_wh){//偏移 [self performSelector:@selector(cAfterMoveFront) withObject:self afterDelay:0.5]; if(mPoint.y > hei_wh*3){ [self performSelector:@selector(cAfterMoveFrontView) withObject:self afterDelay:0.5]; } }else{ heiPoint.y = 0; [UIView animateWithDuration:0.2 animations:^{ [_gBootSV setContentOffset:heiPoint]; } completion:^(BOOL finished){}]; } } }else{ } _gIndexB = _gIndexM; } //手势结束 CGPoint ePoint ; if (recognizer.state == UIGestureRecognizerStateEnded) { _gMoveSVYes = NO; ePoint = recognizer.view.center; int intx = ePoint.x/the_w; int inty = ePoint.y/the_w; _gIndexE = inty*3 + intx; if(_gIndexE > [_gQuickArr count]-1){ _gIndexE = [_gQuickArr count]-1; UIView *theView = (UIView *)[self.view viewWithTag:5000+_gIndexE]; ePoint = theView.center; } CGPoint endPoint = [[_gEntryMarrPoint objectAtIndex:_gIndexE] CGPointValue]; //被拖动V if(_gIndexB < _gIndexE){ //往后方拖 [UIView animateWithDuration:0.3 animations:^{ for(int m = _gIndexB+1;m < _gIndexE+1; m ++){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m-1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m-1; } } completion:^(BOOL finished){}]; }else if(_gIndexB > _gIndexE){ //往前方拖 [UIView animateWithDuration:0.3 animations:^{ for(int m = _gIndexB-1;m > _gIndexE-1; m --){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m+1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m+1; } } completion:^(BOOL finished){}]; }else{} [UIView animateWithDuration:0.15 animations:^{ [_gMoveV setCenter:endPoint]; _gMoveV.tag = 5000+_gIndexE; [_gMoveV setAlpha:1]; } completion:^(BOOL finished){ //首页快捷入口 刷新 [self cQuickEntry]; }]; NSString* path = [self cEntryName]; //更改本地数据 NSDictionary *objB = [_gQuickArr objectAtIndex:_gIndexBM]; NSDictionary *objE = [_gQuickArr objectAtIndex:_gIndexE]; NSInteger indexB = [_gHomeEnterArr indexOfObject:objB]; NSInteger indexE = [_gHomeEnterArr indexOfObject:objE]; if(objB != nil){ [_gHomeEnterArr removeObjectAtIndex:indexB]; [_gHomeEnterArr insertObject:objB atIndex:indexE]; [_gHomeEnterArr writeToFile:path atomically:YES]; } //入口View 数组 存储对象更换位置 UIView *movePanV = [_gPanMArr objectAtIndex:_gIndexBM]; if(movePanV != nil){ [_gPanMArr removeObjectAtIndex:_gIndexBM]; [_gPanMArr insertObject:movePanV atIndex:_gIndexE]; } //首页入口名 获取 [self cEntryName]; } }else{ }}//SV往后移动-(void)cAfterMove{ CGPoint heiPoint = _gBootSV.contentOffset; float hei_wh = _gBootSV.bounds.size.width/3; heiPoint.y = heiPoint.y + hei_wh; [UIView animateWithDuration:0.5 animations:^{ [_gBootSV setContentOffset:heiPoint]; } completion:^(BOOL finished){}];}//拖动控件往后移动-(void)cAfterMoveView{ float hei_wh = _gBootSV.bounds.size.width/3; CGRect tempFrame = _gMoveV.frame; tempFrame.origin.y = tempFrame.origin.y + hei_wh; if(_gMoveSVYes){ NSInteger oneInt = _gIndexM; NSInteger twoInt = _gIndexM+3; //往后方拖 [UIView animateWithDuration:0.3 animations:^{ for(int m = oneInt+1;m < twoInt+1; m ++){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m-1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m-1; } } completion:^(BOOL finished){}]; _gIndexM = twoInt; _gIndexB = twoInt-1; [UIView animateWithDuration:0.5 animations:^{ [_gMoveV setFrame:tempFrame]; } completion:^(BOOL finished){}]; }}//SV往前移动-(void)cAfterMoveFront{ CGPoint heiPoint = _gBootSV.contentOffset; float hei_wh = _gBootSV.bounds.size.width/3; heiPoint.y = heiPoint.y - hei_wh; [UIView animateWithDuration:0.5 animations:^{ [_gBootSV setContentOffset:heiPoint]; } completion:^(BOOL finished){}];}//拖动控件往前移动-(void)cAfterMoveFrontView{ float hei_wh = _gBootSV.bounds.size.width/3; CGRect tempFrame = _gMoveV.frame; tempFrame.origin.y = tempFrame.origin.y - hei_wh; if(_gMoveSVYes){ NSInteger oneInt = _gIndexM; NSInteger twoInt = _gIndexM-3; //往前方拖 [UIView animateWithDuration:0.3 animations:^{ for(int m = oneInt-1;m > twoInt-1; m --){ UIView *midV = (UIView *)[self.view viewWithTag:5000+m]; CGPoint midPoint = [[_gEntryMarrPoint objectAtIndex:m+1] CGPointValue]; [midV setCenter:midPoint]; midV.tag = 5000 + m+1; } } completion:^(BOOL finished){}]; _gIndexM = twoInt; _gIndexB = twoInt+1; [UIView animateWithDuration:0.5 animations:^{ [_gMoveV setFrame:tempFrame]; } completion:^(BOOL finished){}]; }}//删除快捷键-(void)cCancelEntry:(id)sender{ UIButton *tempBut = (UIButton *)sender ; NSInteger index = [[tempBut superview] tag]-5000; //获取本地数据 NSString* path = [self cEntryName]; NSMutableDictionary *tempObjMDict = [[_gQuickArr objectAtIndex:index] mutableCopy]; //删除动画 [self cMoveQuickEntry:index]; //主页入口 数组 [_gHomeEnterArr removeObject:[_gQuickArr objectAtIndex:index]]; [tempObjMDict setObject:@"0" forKey:@"istop"];//修改参数,变为不可展示对象 [_gHomeEnterArr addObject:[tempObjMDict copy]]; [_gHomeEnterArr writeToFile:path atomically:YES];//写入本地 //重新从本地读取数据 [self cEntryName]; //SV自适应高度 [self cChangeEntryVHeight];}//删除后移动入口-(void)cMoveQuickEntry:(NSInteger)theIndex{ if(!_gEntryMarrPoint){ _gEntryMarrPoint = [[NSMutableArray alloc] init]; for (int i = 0; i < [_gQuickArr count]; i ++) { UIView *tempVB = (UIView *)[self.view viewWithTag:5000+i]; CGPoint tempC = tempVB.center; [_gEntryMarrPoint addObject:[NSValue valueWithCGPoint:tempC]]; } } UIView *deleteV = (UIView *)[self.view viewWithTag:5000+theIndex]; [deleteV removeFromSuperview]; [_gPanMArr removeObjectAtIndex:theIndex]; NSInteger count = [_gQuickArr count]; [UIView animateWithDuration:0.5 animations:^{ for(int i = theIndex+1;i < count; i ++){ //要同时改变各个控件的Tag UIView *moveV = (UIView *)[self.view viewWithTag:5000+i]; CGPoint center = [[_gEntryMarrPoint objectAtIndex:i-1] CGPointValue]; [moveV setCenter:center]; moveV.tag = 5000 + i - 1; } } completion:^(BOOL finished){ //删除最后一个中心坐标 [_gEntryMarrPoint removeLastObject]; }];}//解决拖动Bug,添加拖动手势-(void)cBugPanCesture{ //添加拖动手势 for (int i = 0; i < [_gPanMArr count]; i ++) { UIView *tempV = (UIView *)[_gPanMArr objectAtIndex:i]; NSArray *tempArr = tempV.gestureRecognizers; //如果没有添加拖动手势 BOOL result = YES; for (int j = 0; j < [tempArr count]; j ++) { UIGestureRecognizer *tempPan = (UIGestureRecognizer *)[tempArr objectAtIndex:j]; if ([tempPan class] == [UIPanGestureRecognizer class]) { result = NO; } } if(result){ UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cPanGesture:)]; [tempV addGestureRecognizer:panGR]; } }}//长按手势-(void)cLongGestureEntryBut:(UILongPressGestureRecognizer *)recognizer{ //获取本地数据 int count = [_gQuickArr count]; if (recognizer.state == UIGestureRecognizerStateEnded) { }else { if(!_gLongPress){ for (int i = 0; i < count; i ++) { UIView *tempV = (UIView *)[self.view viewWithTag:5000+i]; UIButton *tempBut = (UIButton *)[tempV viewWithTag:4000]; [tempBut setHidden:NO]; } _gLongPress = !_gLongPress; //添加拖动手势 for (int i = 0; i < [_gPanMArr count]; i ++) { UIView *tempV = (UIView *)[_gPanMArr objectAtIndex:i]; UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cPanGesture:)]; [tempV addGestureRecognizer:panGR]; } }else{ for (int i = 0; i < count; i ++) { UIView *tempV = (UIView *)[self.view viewWithTag:5000+i]; UIButton *tempBut = (UIButton *)[tempV viewWithTag:4000]; [tempBut setHidden:YES]; } _gLongPress = !_gLongPress; //移除拖动手势 for (int j = 0; j < [_gPanMArr count]; j ++) { UIView *tempV = (UIView *)[_gPanMArr objectAtIndex:j]; NSArray *tempArr = tempV.gestureRecognizers; for (int k = 0; k < [tempArr count]; k ++) { UIGestureRecognizer *tempPan = (UIGestureRecognizer *)[tempArr objectAtIndex:k]; if ([tempPan class] == [UIPanGestureRecognizer class]) { [tempV removeGestureRecognizer:tempPan]; } } } } }}//长按手势-(void)cLongGestureEntryButCancel:(UILongPressGestureRecognizer *)recognizer{ //获取本地数据 int count = [_gQuickArr count]; if (recognizer.state == UIGestureRecognizerStateEnded) { }else { if(!_gLongPress){ for (int i = 0; i < count; i ++) { UIView *tempV = (UIView *)[self.view viewWithTag:5000+i]; UIButton *tempBut = (UIButton *)[tempV viewWithTag:4000]; [tempBut setHidden:NO]; } _gLongPress = !_gLongPress; //添加拖动手势 for (int i = 0; i < [_gPanMArr count]; i ++) { UIView *tempV = (UIView *)[_gPanMArr objectAtIndex:i]; UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cPanGesture:)]; [tempV addGestureRecognizer:panGR]; } }else{} }}//主页,选择快捷入口-(void)cQuickAction:(UIButton*)sender{ if(!_gLongPress){//是否长按,处于编辑状 }}//弹出栏目-(void)cPopColumnEntry{ //编辑状态 [self cTapRecognizer:nil];}//弹出用户中心-(void)cPopUserCenter{ //编辑状态 [self cTapRecognizer:nil];}//入口数据准备-(NSString *)cEntryName{ NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filename = [path stringByAppendingPathComponent:@"arid"]; //主页入口 数组 if(!_gHomeEnterArr){ _gHomeEnterArr = [[NSMutableArray alloc] init]; } NSMutableArray *filearr = [[NSMutableArray alloc] initWithContentsOfFile:filename]; if(filearr != nil){ _gHomeEnterArr = filearr; } //添加 BOOL result = YES; BOOL result1 = YES; BOOL result2 = YES; for (int i = 0; i < _gHomeEnterArr.count ; i ++) { NSDictionary *subDict = [_gHomeEnterArr objectAtIndex:i]; if([[subDict objectForKey:@"c_name_a"] isEqualToString:@"cs1"]){ result = NO; } if([[subDict objectForKey:@"c_name_a"] isEqualToString:@"cs2"]){ result1 = NO; } if([[subDict objectForKey:@"c_name_a"] isEqualToString:@"cs3"]){ result2 = NO; } } if(result){ NSDictionary *dzdtDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"1409031800",@"addtime",@"测试一",@"c_name",@"cs1",@"c_name_a",@"",@"cid",@"",@"classid",@"",@"count",@"1",@"isdelete",@"1",@"istop",@"",@"listorder",@"",@"parentid", nil]; [_gHomeEnterArr addObject:dzdtDict]; } if(result1){ NSDictionary *dzdtDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"1409031800",@"addtime",@"测试二",@"c_name",@"cs2",@"c_name_a",@"",@"cid",@"",@"classid",@"",@"count",@"1",@"isdelete",@"1",@"istop",@"",@"listorder",@"",@"parentid", nil]; [_gHomeEnterArr addObject:dzdtDict]; } if(result2){ NSDictionary *dzdtDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"1409031800",@"addtime",@"测试三",@"c_name",@"cs3",@"c_name_a",@"",@"cid",@"",@"classid",@"",@"count",@"1",@"isdelete",@"1",@"istop",@"",@"listorder",@"",@"parentid", nil]; [_gHomeEnterArr addObject:dzdtDict]; } //正在展示的对象 if(!_gQuickArr){ _gQuickArr = [[NSMutableArray alloc] init]; } [_gQuickArr removeAllObjects]; for (int j = 0; j < [_gHomeEnterArr count]; j ++) { NSDictionary *tempdict = [_gHomeEnterArr objectAtIndex:j]; NSInteger tempInt = [[tempdict objectForKey:@"istop"] intValue]; if(tempInt == 1){ [_gQuickArr addObject:tempdict]; } } [_gHomeEnterArr writeToFile:filename atomically:YES]; return filename;}@end
图例:
0 0
- IOS开发——页面控件拖动
- iOS开发入门之——拖动视图
- iOS开发入门之——拖动视图
- iOS开发入门之——拖动视图
- iOS开发入门之——可拖动视图
- IOS开发——自定义手势(拖动UIPanGestureRecognizer)
- 黑马程序员——iOS 开发学习---控件制作登录注册页面
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- UIControl IOS控件编程—IOS开发
- 基于网络的客户端开发技巧——第三篇上下拖动切换页面
- 基于网络的客户端开发技巧——第三篇上下拖动切换页面
- 设计你所需要的,而不是你想要的
- 物业知识
- js跳转不兼容问题
- 【每天一个Linux命令】10. 用户账号的新建/修改/删除以及密码修改 useradd/usemod/userdel/passwd
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
- IOS开发——页面控件拖动
- API消息
- jQuery -> 获取/设置HTML或TEXT内容
- 手机支付宝扫一扫 给郝萌主捐赠
- codeforces 431A - Black Square
- 《艾克与金枪鱼》评测:比滑雪大冒险有趣
- 用httpclient做压力测试时Too many open files的解决办法
- putty的复制 技巧
- 网络视听监管政策规定 网络视听进入TV端的挑战 网络视听政策嬗变的逻辑和未来