Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8711379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:51:46+00:00 2026-06-13T04:51:46+00:00

I’m having a trouble with something weird. I’m trying to create a grid of

  • 0

I’m having a trouble with something weird. I’m trying to create a grid of UIViews flipping endlessly. For this purpose, I created the following class:

@implementation LMFlipViewController

@synthesize viewOne=_viewOne, viewTwo=_viewTwo, animationDuration=_animationDuration, pause=_pause, animationFlag=_animationFlag;

-(LMFlipViewController *)initWithViewOne:(UIView *)viewOne viewTwo:(UIView *)viewTwo animationDuration:(CGFloat)animationDuration andPauseInBetweenAnimation:(CGFloat)pause {
    [super init];
    [self.view setFrame:viewOne.bounds];
    _viewOne=viewOne;
    _viewTwo=viewTwo;
    _animationDuration=animationDuration;
    _pause=pause;
    return self;
}

-(void)viewDidLoad{
    [super viewDidLoad];
    NSLog(@"0");
    _animationFlag=NO;
}

-(void)viewDidUnload{
    [super viewDidUnload];
}

-(void)viewWillAppear:(BOOL)animated {
    [self.view addSubview:_viewOne];
//    [self performSelector:@selector(loopAnimation) withObject:nil afterDelay:_pause];
    [NSTimer scheduledTimerWithTimeInterval:_pause
                                     target:self
                                   selector:@selector(loopAnimation)
                                   userInfo:nil
                                    repeats:NO];
    NSLog(@"1");
}

-(void)triggerAnimation {
    NSLog(@"5");
    if (_animationFlag) {
        NSLog(@"Animation flag: YES");
        _animationFlag=NO;
        [UIView transitionWithView:self.view duration:_animationDuration options:(UIViewAnimationOptionTransitionFlipFromLeft) animations: ^{
            [_viewTwo removeFromSuperview];
        } completion:^(BOOL finished) {
            [UIView transitionWithView:self.view duration:_animationDuration options:(UIViewAnimationOptionTransitionFlipFromLeft) animations: ^{
                [self.view addSubview:_viewOne];
            } completion:nil];
        }];
    }else{
        NSLog(@"Animation flag: NO");
        _animationFlag=YES;
        [UIView transitionWithView:self.view duration:_animationDuration options:(UIViewAnimationOptionTransitionFlipFromLeft) animations: ^{
            [_viewOne removeFromSuperview];
        } completion:^(BOOL finished) {
            [UIView transitionWithView:self.view duration:_animationDuration options:(UIViewAnimationOptionTransitionFlipFromLeft) animations: ^{
                [self.view addSubview:_viewTwo];
            } completion:nil];
        }];
    }
    NSLog(@"6");
}

-(void)loopAnimation {
    NSLog(@"2");
    [self triggerAnimation];
    NSLog(@"3");
//    [self performSelector:@selector(loopAnimation) withObject:nil afterDelay:_pause];
    [NSTimer scheduledTimerWithTimeInterval:_pause
                                     target:self
                                   selector:@selector(loopAnimation)
                                   userInfo:nil
                                    repeats:NO];
    NSLog(@"4");
}

@end

Then, I’ve tried this class like this:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *viewOne=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    viewOne.backgroundColor=[UIColor redColor];

    UIView *viewTwo=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    viewTwo.backgroundColor=[UIColor purpleColor];

    LMFlipViewController *flipViewController=[[LMFlipViewController alloc] initWithViewOne:viewOne viewTwo:viewTwo animationDuration:0.5 andPauseInBetweenAnimation:3];
    [self.view addSubview:flipViewController.view];

    UIView *viewThree=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    viewThree.backgroundColor=[UIColor blackColor];

    UIView *viewFour=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    viewFour.backgroundColor=[UIColor blueColor];

    LMFlipViewController *flipViewControllerTwo=[[LMFlipViewController alloc] initWithViewOne:viewThree viewTwo:viewFour animationDuration:0.5 andPauseInBetweenAnimation:3];
    [flipViewControllerTwo.view setFrame:CGRectMake(0, 60, 100, 50)];
    [self.view addSubview:flipViewControllerTwo.view];
}

This way worked perfectly. The point is, I need to instanciate several flip views this way and I need them implemented in a “for” loop. So I tried this:

- (void)viewDidLoad {
    [super viewDidLoad];
    for (int i=0;i<2;i++) {
        UIView *viewOne=[[UIView alloc] initWithFrame:CGRectMake(0, i*60, 100, 50)];
        viewOne.backgroundColor=[UIColor redColor];

        UIView *viewTwo=[[UIView alloc] initWithFrame:CGRectMake(0, i*60, 100, 50)];
        viewTwo.backgroundColor=[UIColor purpleColor];

        [self.view addSubview:[[LMFlipViewController alloc] initWithViewOne:viewOne viewTwo:viewTwo animationDuration:0.5 andPauseInBetweenAnimation:3].view];
    }
}

When I try with the loop, the first view is animating correctly but the others are not. The animation is just skipped and the view switch is made straight.

Does anyone know why ? My guess would be it’s a thread issue or something like this but I’m clueless about these stuffs. Any help is welcomed. Thx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:51:47+00:00Added an answer on June 13, 2026 at 4:51 am

    There is a little inconsistency between the 2 versions of viewDidLoad. I would write the looped one like this:

    - (void)viewDidLoad {
      [super viewDidLoad];
      for (int i=0;i<2;i++) {
        UIView *viewOne=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
        viewOne.backgroundColor=[UIColor redColor];
    
        UIView *viewTwo=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
        viewTwo.backgroundColor=[UIColor purpleColor];
    
        LMFlipViewController *flipViewController=[[LMFlipViewController alloc] initWithViewOne:viewThree viewTwo:viewFour animationDuration:0.5 andPauseInBetweenAnimation:3];
        [flipViewController.view setFrame:CGRectMake(0, i*60, 100, 50)];
        [self.view addSubview:flipViewController.view];
    
      }
    }
    

    Don’t know if this will improve things.

    There is another issue (since you say you are not using ARC): all of your LMFlipViewController objects will leak, since they are alloc/inited and never released (they cannot be, since they are not stored and they reference are simply “lost” after exiting the viewDidLoad method).

    The way around this is keeping an NSMutableArray of all the controllers you instantiate:

    self.flipControllers = [NSMutableArray arrayWithCapacity:...];
    
    ...
    

    and then in viewDidLoad (ARC case):

    [self.flipControllers addObject:[[LMFlipViewController alloc] initWithViewOne:viewOne viewTwo:viewTwo animationDuration:0.5 andPauseInBetweenAnimation:3]];
    [self.view addSubview:[self.flipControllers lastObject].view];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.