xcode: использование подкласса UIImageView с NSTimers

m создание программы, в которой изображение птицы непрерывно падает с верхней части экрана (например, «дождь» птицы). Чтобы иметь NSTimer для каждой отдельной птицы, я создал подкласс UIImageView (называемый "BirdUIImageView»). Однако я'я не уверен, как правильно реализовать код - куда и что ставить и т. д.

Вот код, который я имею в ViewController.m:

#import "ViewController.h"

#import "BirdUIImageView.h"

@interface ViewController ()

@end

@implementation ViewController {

    BirdUIImageView *_myImage;

}

- (void)viewDidLoad
{


    //IMAGE CREATOR TIMER
    createImagesTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(createImages) userInfo:nil repeats:YES];

}


  //CREATES AN IMAGE
-(void) createImages {  
    srand(time(NULL));
    int random_x_coordinate = rand() % 286;
    CGRect myImageRect = CGRectMake(random_x_coordinate, 0.0f, 40.0f, 40.0f);
    BirdUIImageView *myImage = [[BirdUIImageView alloc] initWithFrame:myImageRect];
    [myImage setImage:[UIImage imageNamed:@"flake.png"]];
    myImage.opaque = YES;
    [self.view addSubview:myImage];
    _myImage = myImage;

}

И вот код, который я имею в BirdUIImageView.m. Я'Я совершенно не знаю, что делать в этом файле, но я попытался:

#import "BirdUIImageView.h"



@implementation BirdUIImageView  


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)viewDidLoad
{
    //FALLING BIRDS TIMER
    moveObjectTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(moveObject) userInfo:nil repeats:YES];
}

//FALLING BIRDS MOVER
-(void) moveObject {

    _myImage.center = CGPointMake(_myImage.center.x, _myImage.center.y +1);

}

Ответы на вопрос(1)

Ваш ответ на вопрос