2012-01-16 129 views
0

下一个按钮仅适用于2张图像我有10张图片后两张图片不能前进前一个按钮适用于所有图像,但下一个按钮只适用于一个和第二个图像 下面是下一个按钮代码UIScrollView下一个上一个按钮

 - (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]; 



     } 

回答

4

更换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; 
    } 
    } 
+0

感谢它为我工作一件事我要问,如果我保存在数据库中这一形象也仅保存其在索引一个图像只有我可以发表上述 – 2012-01-16 11:11:48

+0

的代码你看到我编辑的代码为保存图像 – 2012-01-17 08:58:14

+0

其真正的作品很好....谢谢 – svmrajesh 2014-05-17 06:04:40

1
- (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; 
    } 

} 
相关问题