UIScrollView следующая предыдущая кнопка - PullRequest
0 голосов
/ 16 января 2012

следующая кнопка работает только для 2 изображений, у меня есть 10 изображений в массиве после двух изображений, она не перемещается вперед, предыдущая кнопка работает для всех изображений, но следующая кнопка работает только для одного и второго изображения. Ниже приведен код следующей кнопки

       - (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x <= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
    frame.origin.y = 0;
     frame.size = self.scrollView.frame.size;
     [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
       }

     }


 // Here is the previous button code


      -(IBAction)previousButtonAction
    {


    if ( self.scrollView.contentOffset.x >= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x -self.scrollView.frame.size.width;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
   } 
   }

Добавление изображений в базу данных

     -(IBAction)addToCollectionButtonAction{




      GeoNewsAppDelegate *appDelegate = (GeoNewsAppDelegate *)[[UIApplication   sharedApplication] delegate];

   // Create a Coffee Object.
    Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:0];

    int pageNumber  = [pageControl currentPage]; 
   NSLog(collectionImage);


   RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:pageNumber];




    NSString*thumb2=aRowTwo.image;

    coffeeObj.thumb = thumb2;
   coffeeObj.path = thumb2; 





         [appDelegate addCoffee:coffeeObj];



      }

Ответы [ 2 ]

4 голосов
/ 16 января 2012

Заменить self.scrollView.frame.size.width на self.scrollView.contentSize.width

    - (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x <= self.scrollView.contentSize.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
    frame.origin.y = 0;
     frame.size = self.scrollView.frame.size;
     [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
       }

     }


 // Here is the previous button code


      -(IBAction)previousButtonAction
    {


    if ( self.scrollView.contentOffset.x >= self.scrollView.frame.size.width ) {
    CGRect frame;
    frame.origin.x = self.scrollView.contentOffset.x -self.scrollView.frame.size.width;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    [self.scrollView scrollRectToVisible:frame animated:YES];
    pageControlBeingUsed = YES;
   } 
   }
1 голос
/ 16 января 2012
- (IBAction)  nextButtonAction {

    if ( self.scrollView.contentOffset.x < (self.scrollView.frame.size.width*10) ) {
        CGRect frame;
        frame.origin.x = self.scrollView.contentOffset.x +self.scrollView.frame.size.width;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        [self.scrollView scrollRectToVisible:frame animated:YES];
        pageControlBeingUsed = YES;
    }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...