2017-01-03 3 views
0
//add the scrollview to the view 
Friend_Request_Scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-60,70,120,140)]; 
[Friend_Request_Scroll setAlwaysBounceVertical:NO]; 
Friend_Request_Scroll.delegate=self; 
Friend_Request_Scroll.pagingEnabled=YES; 
[Friend_Request_Scroll setShowsHorizontalScrollIndicator:NO]; 
[Friend_Request_Scroll setShowsVerticalScrollIndicator:NO]; 
CGFloat xOrigin = 0; 

for (int i = 0; i <[imageCollection count]; i++) { 

    Back_Request_Scroll=[[UIView alloc]init]; 
    Back_Request_Scroll.frame=CGRectMake(xOrigin,Friend_Request_Scroll.frame.origin.y-135,120,140); 
    Back_Request_Scroll.backgroundColor=[UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:0.5]; 
    Back_Request_Scroll.clipsToBounds=YES; 
    [Friend_Request_Scroll addSubview:Back_Request_Scroll]; 

    image = [[UIImageView alloc] initWithFrame: 
      CGRectMake(0, 0, 
         Back_Request_Scroll.frame.size.width, 
         Back_Request_Scroll.frame.size.height)]; 
    [image sd_setImageWithURL:[imageCollection objectAtIndex:i]    placeholderImage:[UIImage imageNamed:@""]]; 

    image.tag=i; 
    [Back_Request_Scroll addSubview:image]; 
    xOrigin= xOrigin+120; 
    image.userInteractionEnabled=YES; 

} 
Friend_Request_Scroll.contentSize = CGSizeMake(xOrigin, 
              0); 
[self.view addSubview:Friend_Request_Scroll]; 


swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)]; 
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft; 
[image addGestureRecognizer:swipeleft]; 


swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)]; 
swiperight.direction=UISwipeGestureRecognizerDirectionRight; 
[image addGestureRecognizer:swiperight]; 


pageControl = [[UIPageControl alloc] init]; 
pageControl.frame = CGRectMake(self.view.frame.size.width/2-60,Friend_Request_Scroll.frame.size.height+Friend_Request_Scroll.frame.origin.y,image.frame.size.width,20); 
pageControl.numberOfPages = [imageCollection count]; 
pageControl.currentPage = currentValue; 
[pageControl addTarget:self action:@selector(changePage) forControlEvents:UIControlEventValueChanged]; 
[self.view addSubview:pageControl]; 

Antwort

0

Probieren Sie diesen Code aus, Sie verwenden Recipiizer Objektansicht Tag.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    [self.view addSubview:scroll]; 

    NSInteger i; 
    for (i=0; i<20; i++) 
    { 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*90 + i*15, 300, 90)]; 
     imageView.backgroundColor = [UIColor blackColor]; 
     imageView.userInteractionEnabled = YES; 
     imageView.tag = i; 

     NSLog(@“image Tag = %d”, imageView.tag); 

     [scroll addSubview:imageView]; 

     UISwipeGestureRecognizer *recognizer; 

    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)]; 
     [imageView addGestureRecognizer: recognizer]; 

    } 

    scroll.contentSize = CGSizeMake(320, 110*i); 

} 
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 
    NSLog(@"Swipe received."); 
NSLog(@“image Tag = %d”, recognizer.view.tag); 
} 

aktualisieren Kein Swipe Notwendigkeit.

- (void)scrollViewDidScroll:(UIScrollView *)sender { 
    if (sender == scroll) { 
     int pageNum = (int)(scroll.contentOffset.x/scroll.frame.size.width); 
     NSLog(@"%d",pageNum); 
     //self.pagecontroller.currentPage =pageNum; 
    } 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height)]; 
    scroll.delegate = self; 
    scroll.pagingEnabled = YES; 
    [self.view addSubview:scroll]; 
    CGFloat currentXOffset = 0; 
    NSInteger i; 
    for (i=0; i<3; i++) 
    { 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(currentXOffset, 100, self.view.frame.size.width, 200)]; 
     if (i == 0){ 
      imageView.backgroundColor = [UIColor blackColor]; 
     }else if (i == 1){ 
      imageView.backgroundColor = [UIColor orangeColor]; 

     }else if (i == 2){ 
      imageView.backgroundColor = [UIColor grayColor]; 

     } 
     imageView.userInteractionEnabled = YES; 
     imageView.tag = i; 
     currentXOffset = currentXOffset + imageView.frame.size.width; 

     [scroll addSubview:imageView]; 

//  UISwipeGestureRecognizer *recognizer; 
//   
//  recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 
//  [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionUp)]; 
//  [imageView addGestureRecognizer: recognizer]; 

    } 

    scroll.contentSize = CGSizeMake(currentXOffset, self.view.frame.size.height); 
} 
+0

kartik es zu tauschen arbeiten, aber nicht für jedes Mal –

+0

Immer, wenn ich versuche, nach links oder rechts wischen funktioniert es nicht richtig –

+0

können Sie Ihre Aufgabe Ziel? Möchten Sie aktuelle Bildansicht Tag ah beim Streichen – karthikeyan

0

Add Tippgeste Aktion auf das Bild und Sie können den Tag mit [Absender tag] erhalten

+0

keine Tippgeste i ein einzelnes Bild in Imageview von Scrollview angezeigt werden soll, und dann will die Paginierung Punkte –

0

Ich habe nur wenige Image jeder von ihnen haben Tag und ich habe eine Reihe von Bildern. Wenn der Benutzer auf ein Bild klickt, erhalte ich ein Bild-Tag und ergreife Maßnahmen.

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    [self.view addSubview:scroll]; 

    NSInteger i; 
    for (i=0; i<20; i++) 
    { 
     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, i*90 + i*15, 300, 90)]; 
     imageView.backgroundColor = [UIColor blackColor]; 
     imageView.userInteractionEnabled = YES; 
     imageView.tag = i; 

     NSLog(@“image Tag = %d”, imageView.tag); 

     [scroll addSubview:imageView]; 

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(findTheTag:)]; 
     [imageView addGestureRecognizer:tap]; 

    } 

    scroll.contentSize = CGSizeMake(320, 110*i); 

} 
- (void)findTheTag:(id)sender 
{ 

    NSLog(@“image Tag = %d”, sender.tag); 


} 
+0

Herr ankur Ich möchte Wert-Tag ändern, wenn ich versuche, links oder rechts –

2

Versuchen Sie diese Delegiertenmethode.Dieser Delegat wird Ihnen sagen, dass das Scrollen beendet wurde.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
Verwandte Themen