teena
teena

Reputation: 41

Animation to UIImageView in objective-c

I am new to this field. I have used 8 UIImageView inside the UIVIEW.

    @property(weak,nonatomic)IBOutlet UIImageView *b1;
    @property(weak,nonatomic)IBOutlet UIImageView *b2;
    @property(weak,nonatomic)IBOutlet UIImageView *b3;
    @property(weak,nonatomic)IBOutlet UIImageView *b4;


    @property(weak,nonatomic)IBOutlet UIImageView *Bb1;
    @property(weak,nonatomic)IBOutlet UIImageView *Bb2;
    @property(weak,nonatomic)IBOutlet UIImageView *Bb3;
    @property(weak,nonatomic)IBOutlet UIImageView *Bb4;
@property(weak,nonatomic)IBOutlet UIView *VVV;

I NEED : WHEN THE UIViewController LOAD first 4 UIImageView (b1,b2,b3,b4 images)should display which is already set .then after 5s this 4 UIImageView should flip (for b1 img it should display the Bb1 img, same case for b2 img after flip it should display Bb2 img, same for b3-Bb3,b4-Bb4 img)then after flip for 5s it should display the b1,b2,b3,b4 img in UIImageView.

IMP:I NEED WHILE

viewDidLoad

not in button action .

Upvotes: 0

Views: 1562

Answers (1)

lem
lem

Reputation: 100

You don't need to create Bb1-4 views to flip images in UIImageView. In general there are different ways to make transition from one image to another. Some of them are described in this answer(not mine, credits go to sergio): UIView flip animation

Also there is a way to animate .image change in UIImageView:

+ (void)transitionWithView:(UIView *)view
              duration:(NSTimeInterval)duration
               options:(UIViewAnimationOptions)options
            animations:(void (^)(void))animations
            completion:(void (^)(BOOL finished))completion

Check apple docs about this: https://developer.apple.com/documentation/uikit/uiview/1622451-animatewithduration

Example of usage:

UIImage *imageOne = [UIImage imageNamed:@"b1"];
UIImage *imageTwo = [UIImage imageNamed:@"bb1"];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
imageView.image = imageOne;

[UIView transitionWithView:imageView
                  duration:2.0
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{
                    imageView.image = imageTwo;
                } completion:nil];

Here imageView is animating from imageOne to imageTwo with flip.

Upvotes: 1

Related Questions