1

如何在 iPhone 中只滚动一侧?我必须停止向后滚动这是我的代码

 - (void)layoutScrollImages
  {
   // int n = 1 + arc4random() % 10 + 10;

UIImageView *view = nil;
NSArray *subviews = [FirstScrollView subviews];

// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
    if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
    {
        CGRect frame = view.frame;
        frame.origin = CGPointMake(curXLoc, 0);
        view.frame = frame;

        curXLoc += (kScrollObjWidth);
    }
}

// set the content size so it can be scrollable
 [FirstScrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [FirstScrollView bounds].size.height)];

   }

 - (void)viewDidLoad
  {




self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];



// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[FirstScrollView setBackgroundColor:[UIColor blackColor]];
[FirstScrollView setCanCancelContentTouches:NO];
FirstScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
FirstScrollView.clipsToBounds = YES;        // default is NO, we want to restrict drawing within our scrollview



   FirstScrollView.scrollEnabled = YES;
   FirstScrollView.pagingEnabled = YES;
   FirstScrollView.bounces = NO;

   FirstScrollView.directionalLockEnabled = YES;



  // [FirstScrollView setContentOffset:CGPointMake(x, y) animated:YES];

   [FirstScrollView setShowsHorizontalScrollIndicator:NO];
   [FirstScrollView setShowsVerticalScrollIndicator:NO];





  // FirstScrollView.scrollEnabled = YES;


   int n = 1 + arc4random() % 10 + 10;

   NSString *string = [NSString stringWithFormat:@"%i",n];

   //lbl.text = string;

NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{


   // [kNumImages addObject:[NSNumber numberWithInt:i]];
    NSString *imageName = [NSString stringWithFormat:@"%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    CGRect rect = imageView.frame;
    rect.size.height = kScrollObjHeight;
    rect.size.width = kScrollObjWidth;
    imageView.frame = rect;
    imageView.tag = i;  
    lbl.text = string;
    [FirstScrollView addSubview:imageView];
    [imageView release];


         if(n == i){



             //break;

             [self showAlert];
             break;


        }
     }
4

0 回答 0