Добавление анимации на страницу в ScrollView - PullRequest
1 голос
/ 19 октября 2010

У меня есть анимация (в настоящее время повторяется 30 различных изображений), и я хочу добавить ее на одну страницу в ScrollView (в настоящее время содержит 7 страниц).Можно ли это сделать?

Я добавил свой код ниже, поведение, которое я получаю, заключается в том, что на выбранной странице ничего не появляется, на всех других страницах я получаю изображения как обычно, но должно бытьчто-то не так с моим addAnimation методом, которого я не вижу.Может кто-нибудь, пожалуйста, посмотрите на это и скажите мне, что я делаю неправильно ... Боюсь, что это очевидная ошибка, я уже давно смотрю на это.

ViewController.m

- (void)loadView {
    //holds the pages
 pageArray = [[NSMutableArray alloc] init];  
 [self setUpView];
}
- (void)setUpView {
 //INITIALISE PAGING SCROLL VIEW
 CGRect pagingScrollViewFrame = [[UIScreen mainScreen] bounds];
 pagingScrollViewFrame.origin.x = 0;
 pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
 pagingScrollView.contentMode =  UIViewContentModeScaleAspectFit;

 //CONFIGURE PAGING SCROLL VIEW 
 pagingScrollView.pagingEnabled = YES;
 pagingScrollView.backgroundColor = [UIColor whiteColor];
 pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width*7, pagingScrollViewFrame.size.height);

 //ACTIVATE PAGING SCROLL VIEW
 self.view = pagingScrollView;

 //ADD PAGES TO SCROLL VIEW
 for (int i = 0; i < 7; i++){
  ImageScrollView *page = [[[ImageScrollView alloc] init] autorelease];
  [self configurePage:page forIndex:i];
  [pagingScrollView addSubview:page];
            //adds pages here for reference in other methods
  [pageArray addObject:page];
 }
}
- (void)configurePage:(ImageScrollView *)page forIndex:(NSUInteger)index
{
    page.index = index;
    page.frame = [self frameForPageAtIndex:index];
    //if the image is id number 4 add an animation, if not, add an image as normal
 if (index == 4){
  [self addAnimation:page];
 }else {
  [page displayImage:[self imageAtIndex:index]];
 }

}
- (void)addAnimation:(ImageScrollView *)page{
    //I got this code from a tutorial on animation, I'm trying to add this UIImageView to my ScrollView

    // make a new UIImageView for the new image
    UIImageView* animationView = [[UIImageView alloc] init];
 // load all the frames of our animation
 animationView.animationImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"pin clip0000.jpg"],
          [UIImage imageNamed:@"pin clip0001.jpg"],
          [UIImage imageNamed:@"pin clip0002.jpg"],
          [UIImage imageNamed:@"pin clip0003.jpg"],
          [UIImage imageNamed:@"pin clip0004.jpg"],
          [UIImage imageNamed:@"pin clip0005.jpg"],
          [UIImage imageNamed:@"pin clip0006.jpg"],
          [UIImage imageNamed:@"pin clip0007.jpg"],
          [UIImage imageNamed:@"pin clip0008.jpg"],
          [UIImage imageNamed:@"pin clip0009.jpg"],
          [UIImage imageNamed:@"pin clip0010.jpg"],
          [UIImage imageNamed:@"pin clip0011.jpg"],
          [UIImage imageNamed:@"pin clip0012.jpg"],
          [UIImage imageNamed:@"pin clip0013.jpg"],
          [UIImage imageNamed:@"pin clip0014.jpg"], 
          [UIImage imageNamed:@"pin clip0015.jpg"],
          [UIImage imageNamed:@"pin clip0016.jpg"],
          [UIImage imageNamed:@"pin clip0017.jpg"],
          [UIImage imageNamed:@"pin clip0018.jpg"],
          [UIImage imageNamed:@"pin clip0019.jpg"],
          [UIImage imageNamed:@"pin clip0020.jpg"],
          [UIImage imageNamed:@"pin clip0021.jpg"],
          [UIImage imageNamed:@"pin clip0022.jpg"],
          [UIImage imageNamed:@"pin clip0023.jpg"],
          [UIImage imageNamed:@"pin clip0024.jpg"],
          [UIImage imageNamed:@"pin clip0025.jpg"],
          [UIImage imageNamed:@"pin clip0026.jpg"],
          [UIImage imageNamed:@"pin clip0027.jpg"],
          [UIImage imageNamed:@"pin clip0028.jpg"],
          [UIImage imageNamed:@"pin clip0029.jpg"],
          nil];

 // all frames will execute in 1 second
 animationView.animationDuration = 1;
 // repeat the annimation forever
 animationView.animationRepeatCount = 0;
 // start animating
 [animationView startAnimating];
    [page addSubview:animationView];
 [animationView release];

}

1 Ответ

0 голосов
/ 19 октября 2010

Я не добавил рамку к анимации. Я добавил это к методу addAnimation:

CGRect animationFrame;

animationFrame = page.frame;
animationFrame.origin.x = 0;

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