ios - Swipe Left and Right to load item -
i had array contains 10 items 1,2,3,4,5,6,7,8,9,10. when load page item @ 3. when user swipe left go 4 , swipe right go 2. may know how it?
newsid=[[nsmutablearray alloc]init]; [newsid addobject:@"1"]; [newsid addobject:@"2"]; [newsid addobject:@"3"]; [newsid addobject:@"4"]; [newsid addobject:@"5"]; [newsid addobject:@"6"]; [newsid addobject:@"7"]; [newsid addobject:@"8"]; [newsid addobject:@"9"]; [newsid addobject:@"10"]; uiswipegesturerecognizer * swipeleft= [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swipeleft:)]; swipeleft.direction=uiswipegesturerecognizerdirectionleft; [self.view addgesturerecognizer:swipeleft]; uiswipegesturerecognizer * swiperight= [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(swiperight:)]; swiperight.direction=uiswipegesturerecognizerdirectionright; [self.view addgesturerecognizer:swiperight];
try this. taking 1 uilabel , changing text of while swiping.and 1 int variable keep track of swipe.
- (void)viewdidload { [super viewdidload]; newidarray = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10"]; num_index = 3; valuelabel.text = [newidarray objectatindex:num_index]; leftgesture = [[uiswipegesturerecognizer alloc]init]; leftgesture.direction = uiswipegesturerecognizerdirectionleft; [leftgesture addtarget:self action:@selector(performswipegesture:)]; [self.view addgesturerecognizer:leftgesture]; rightgesture = [[uiswipegesturerecognizer alloc]init]; rightgesture.direction = uiswipegesturerecognizerdirectionright; [rightgesture addtarget:self action:@selector(performswipegesture:)]; [self.view addgesturerecognizer:rightgesture]; } - (ibaction)performswipegesture:(uiswipegesturerecognizer *)sender { if (sender.direction == uiswipegesturerecognizerdirectionleft) { if (num_index <9) { num_index = num_index +1; valuelabel.text = [newidarray objectatindex:num_index]; } } else if (sender.direction == uiswipegesturerecognizerdirectionright) { if (num_index >0) { if (num_index >1) num_index = num_index -2; else num_index = num_index -1; valuelabel.text = [newidarray objectatindex:num_index]; } } }
Comments
Post a Comment