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

  • Home
  • SEARCH
  • 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 8916365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:13:35+00:00 2026-06-15T05:13:35+00:00

Based on an earlier stackoverflow suggestion, I am trying to create a playing card

  • 0

Based on an earlier stackoverflow suggestion, I am trying to create a playing card using CALayers added to a CATransformLayer. The idea is to create front and back CALayers and combine them in the CATransformLayer which can then be rotated, flipped, etc, with the proper side automatically showing. Below is example code trying to create a single card with a green front and a red back.

The red back is flipped about the Y-axis so that it is facing away from the green front. The green front calayer has a “higher” Z location than the red back.

When I do the transform though, I am simply seeing the card in what appears to be its non-flipped state. Any ideas where I am going wrong here?

#define DEGREES_TO_RADIANS(angle) (angle * M_PI / 180.0)

- (void)viewDidLoad
{
    [super viewDidLoad];

    CATransformLayer *cardContainer = [CATransformLayer layer];

    cardContainer.bounds = CGRectMake(0,0, 150,200);


    CALayer *cardFront  = [CALayer layer];
    cardFront.frame     = cardContainer.bounds;

    cardFront.backgroundColor = [UIColor greenColor].CGColor;
    cardFront.borderColor = [UIColor blackColor].CGColor;
    cardFront.borderWidth = 2.0;
    cardFront.cornerRadius = 30.0;
    cardFront.zPosition = 2; // Put front of card on top relative to back of card
    cardFront.doubleSided = NO;
    [cardContainer addSublayer:cardFront];

    CALayer *cardBack  = [CALayer layer];
    cardBack.frame     = cardContainer.bounds;
    cardBack.backgroundColor = [UIColor redColor].CGColor;
    cardBack.zPosition = 1;
    cardBack.doubleSided = NO;

    // Flip cardBack image so it is facing outward and visible when flipped
    cardBack.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(180),0.0,1.0,0.0);
    [cardContainer addSublayer:cardBack];

    UIView* cardView = [[UIView alloc] initWithFrame:cardContainer.bounds];
    cardView.center = CGPointMake(self.view.center.x, self.view.center.y);
    [cardView.layer addSublayer:cardContainer];
    [self.view addSubview:cardView];

    // Show the card flipped over (desired the red side to be showing, but instead shows green)
    cardView.layer.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(180),0.0,1.0,0.0);

}
  • 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-15T05:13:36+00:00Added an answer on June 15, 2026 at 5:13 am

    Found the problem, you must apply the transform to the sublayerTransform property, as in:

    cardView.layer.sublayerTransform = …

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

Sidebar

Related Questions

Based on earlier thread with same argument i am trying to fit a stable
I'm trying to create an AS3 pure preloader based on the [frame] metadata/compiler tag,
Based on one answer to an earlier post , I'm investigating the possibility of
I'm working on a basic google applications based system. Like I earlier defined I'm
This is a knowledge topic based on an earlier question I had today. These
Folks I am implementing a file based queue ( see my earlier question )
We have recently implemented htmlpurifier in our web-based application. Earlier we used to have
Based on an earlier post , I've written the following code. Please excuse the
I'm using python 2.7, and trying to run some CPU heavy tasks in their
This is a more specific question based on a question I asked earlier... If

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.