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 7958957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:29:58+00:00 2026-06-04T04:29:58+00:00

I’ve got this code, what I want it to do, is to create a

  • 0

I’ve got this code, what I want it to do, is to create a few UIViews on the screen, with a button on them, and when you click on the button that is located on-top of the UIView, the UIView it self will perform animation and will flip to the other side, when you click on the button that is on the UIView’s other side, again, it will flip back.

So i’ve created my UIView’s dynamically, but I have a problem, the button is performing the action, but the view wont performing the animation because I dont know how to reach out to the specific UIView.

How can I do it?

-(void)viewDidLoad
{
    arrImages = [NSMutableArray arrayWithObjects:[UIImage imageNamed:@"image001.jpg"],[UIImage imageNamed:@"image002.jpg"],[UIImage imageNamed:@"image003.jpg"],[UIImage imageNamed:@"image004.png"],[UIImage imageNamed:@"image005.JPG"],[UIImage imageNamed:@"image006.jpg"],[UIImage imageNamed:@"image007.jpeg"],[UIImage imageNamed:@"image008.jpg"],[UIImage imageNamed:@"image009.jpg"],[UIImage imageNamed:@"image010.png"],[UIImage imageNamed:@"image001.jpg"],[UIImage imageNamed:@"image002.jpg"],[UIImage imageNamed:@"image003.jpg"],[UIImage imageNamed:@"image004.png"],[UIImage imageNamed:@"image005.JPG"],[UIImage imageNamed:@"image006.jpg"],[UIImage imageNamed:@"image007.jpeg"],[UIImage imageNamed:@"image008.jpg"],[UIImage imageNamed:@"image009.jpg"],[UIImage imageNamed:@"image010.png"], nil];

    x = 0;
    btnFrameX = 18;
    btnFrameY = 20;

    for (int i = 0; i < [arrImages count]; i++)
    {
        if (btnFrameX <= 237)
        {
            //  Create views of cards

            UIView * first = [[UIView alloc]initWithFrame:CGRectMake(btnFrameX, btnFrameY, 65, 65)];
            UIView * secod = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 65, 65)];
            UIView * third = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 65, 65)];

            first.tag = [[NSString stringWithFormat:@"1%i",i]intValue];
            secod.tag = [[NSString stringWithFormat:@"2%i",i]intValue];
            third.tag = [[NSString stringWithFormat:@"3%i",i]intValue];

            NSLog(@"1%i",i);
            NSLog(@"2%i",i);
            NSLog(@"3%i",i);

            UILabel * cardLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 65, 65)];
            cardLabel.text = [NSString stringWithFormat:@"%i",i+1];

            UIButton * cardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [cardBtn setFrame:CGRectMake(0, 0, 65, 65)];
            [cardBtn setTitle:[NSString stringWithFormat:@"%i",i] forState:UIControlStateNormal];
            [cardBtn setImage:[arrImages objectAtIndex:i] forState:UIControlStateNormal];

            [cardBtn addTarget:self action:@selector(flipView:) forControlEvents:UIControlEventTouchUpInside];

            [secod addSubview:cardLabel];
            [third addSubview:cardBtn];
            [first addSubview:secod];
            [first addSubview:third];
            [self.view addSubview:first];

            btnFrameX = btnFrameX + 73;
        }
        if (btnFrameX > 237)
        {
            btnFrameX = 18;
            btnFrameY = btnFrameY + 73;
        }
    }


-(IBAction) flipView:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    // Should hide the one that you clicked on and show the other one.
    [self showOtherView];
    // flipping the mainview (first), he's the one that the other 2 UIViews (second and third) attached on.
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:first cache:YES];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
}

-(void) showOtherView
{    
    if (x == 0)
    {
        x = 1;
        second.hidden = NO;
        third.hidden = YES;
    }
    else
    {
        x = 0;
        second.hidden = YES;
        third.hidden = NO;
    }
}

I hope I explained myself well, If not, please ask me and I will answer.

Thanks alot!

  • 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-04T04:29:58+00:00Added an answer on June 4, 2026 at 4:29 am

    Your button is subview of the UIView you want to reach, isn’t it ?

    If so, it s very simple : set a selector and target to your button,

    [cardBtn addTarget:self action:@selector(flipView:) forControlEvents:UIControlEventTouchUpInside];
    

    Declare your function,

    -(void)flipView:(UIButton*)sender;
    

    The clicked button will be in the sender parameter. So :

    -(void)flipView:(UIButton*)sender {
        UIView * reachedView = [sender superview];
        /* make what you want with the reached view ! */
    }
    

    EDIT :

    In your description, you want two buttons: one on each side. 1st side is viewA and 2nd side is viewB. viewA & viewB belong to mainView.

    UIButton btA = ...
    UIButton btB = ...
    [btA addTarget:self action:@selector(flipView:) forControlEvents:UIControlEventTouchUpInside];
    [btB addTarget:self action:@selector(flipView:) forControlEvents:UIControlEventTouchUpInside];
    [viewA addSubview:btA];
    [viewB addSubview:btB];
    [mainView addSubview:viewA];
    [mainView addSubview:viewB];
    

    now in flip view :

    -(void)flipView:(UIButton*)sender {
        UIView * mainView = [[sender superview] superview]; // the first for viewA or B, the second for mainView...
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
        [mainView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
        [UIView commitAnimations];
    }
    

    Does it correspond to your problem ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.