下一个按钮仅适用于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];
}
答案 0 :(得分: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;
}
}
答案 1 :(得分: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;
}
}