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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:41:01+00:00 2026-06-08T08:41:01+00:00

From a couple of previous StackOverFlow questions and this example on github CA360 ,

  • 0

From a couple of previous StackOverFlow questions and this example on github CA360, I’ve managed to simulate a flipping card with an image on the “front” and text on the back. However, the text on the back of the card is upside down and I only got it to center horizonatally. How can I orient the text properly and center it vertically on my card?

Card front:

enter image description here

Card back (How to orient and center text vertically?):

enter image description here

[Update]

I set the opacity on my top layer to 0.5 then I got the idea to just “pre-flip” the back layer so that when the actual flip happened that it would just reset it back to normal.

enter image description here

My “pre-flip” looks like this:

cardBack.transform = CATransform3DMakeRotation(M_PI, 1.0f, 0.0f, 0.0f); // Pre-flip card

Now I just need to find a built-in way to vertical setting or do it the hard way… Half the distance…font height… plus…

Set up card container with 2 layers
(Reference):


    - (void)loadView {
        UIView *myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        myView.backgroundColor = [UIColor whiteColor];

        self.view = myView;

        cardContainer = [CATransformLayer layer];
        cardContainer.frame = CGRectMake(300, 250, 200, 150);


        CALayer *cardFront  = [CALayer layer];
        cardFront.frame     = cardContainer.bounds;
        cardFront.zPosition = 5;   // Higher than the zPosition of the back of the card
        cardFront.contents  = (id)[UIImage imageNamed:@"Ben"].CGImage;
        cardFront.opacity = 0.5;

        [cardContainer addSublayer:cardFront];

        /*
         https://stackoverflow.com/questions/2209734/add-text-to-calayer
         */

        CATextLayer *cardBack  = [CATextLayer layer];
        cardBack.string = @"Hello";
        cardBack.frame     = cardContainer.bounds;
        cardBack.zPosition = 4;
        cardBack.backgroundColor = [[UIColor grayColor] CGColor];
        cardBack.alignmentMode = kCAAlignmentCenter;
        CFTypeRef *font = (CFTypeRef *)CTFontCreateWithName(CFSTR("Times"), 48, NULL);
        cardBack.font = font;
        [cardContainer addSublayer: cardBack];

        [self.view.layer addSublayer:cardContainer];

    }

Code borrowed from another SOF question to flip card:


    - (void) flipCard {
    //    [self.flipTimer invalidate];
    //    if (flipped){
    //        return;
    //    }
        NSLog(@"Count=%d", count);
        id animationsBlock = ^{
    //        self.backView.alpha = 1.0f;
    //        self.frontView.alpha = 0.0f;
    //        [self bringSubviewToFront:self.frontView];
    //        flipped = YES;
            NSLog(@"Flipping...");
            CALayer *layer = cardContainer;
            CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
           rotationAndPerspectiveTransform.m34 = 1.0 / 500;

            if (count == 0) {


                rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI, 1.0f, 0.0f, 0.0f);
            } else {  // flip it back to image

                rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, 0.0f, 0.0f, 1.0f, 1.0f);

            }
            layer.transform = rotationAndPerspectiveTransform;
        };
        count = (count + 1) % 2;

        [UIView animateWithDuration:1.25
                              delay:0.0
                            options: UIViewAnimationCurveEaseInOut
                         animations:animationsBlock
                         completion:nil];

    }

  • 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-08T08:41:03+00:00Added an answer on June 8, 2026 at 8:41 am

    Are you aware of the UIView class method:

    • (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

    You would have two views, the front and the back. both can be in your nib. With this call, you can flip from one view to the other view with almost no effort.

    EDIT: I did look at your code. Note that anchorPoint, position, and bounds all play together, but you can still use frame. Its interesting (dare I say fun) to play with changing one and seeing how the others change.

    What I ended up doing is comment out all setting of position and frame, and essentially set the text box frame as I would with a UIView (width of large view minus width of small view divided by 2,etc):

    cardBackText.frame = CGRectMake((200-100)/2, (150-30)/2, 100,30); // 200, 150
    NSLog(@"position=%@ anchorPoint=%@ bounds=%@", NSStringFromCGPoint(cardBackText.position),NSStringFromCGPoint(cardBackText.anchorPoint),NSStringFromCGRect
    

    The log printed this out:

    position={100, 75} anchorPoint={0.5, 0.5} bounds={{0, 0}, {100, 30}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A couple of questions re static classes. Some of this is from stuff I
I have tried a couple of solutions from previous questions, but no luck. Hoping
A couple of questions really about the code below from which I gained assistance
This question attempts to combine knowledge gained from some previous answers on SO, so
From couple of days i am thinking of a following scenario Consider I have
From a couple of my Assemblys like AssemblyA, AssemblyB, AssemblyC, AssemblyD I am calling
I want to generate an HTML table from a couple specified parameters. Specifically, the
I need to move a huge amount of data from a couple tables in
i want to extract couple of tables from a web page and show them
I have couple of formulas and data coming from database. I want to refresh

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.