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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:43:57+00:00 2026-06-01T12:43:57+00:00

I am implementing a simple iOS solitaire game that allows the user to drag

  • 0

I am implementing a simple iOS solitaire game that allows the user to drag the cards around in the usual way. The cards are represented with the UIView subclass CardView. All the card view’s are siblings which are subviews of SolitaireView. The following snippet tries to “bring a card to the front” so that it is above all the other views as it is being dragged:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   UITouch *touch = [touches anyObject];
   if (touch.view.tag == CARD_TAG) {
      CardView *cardView = (CardView*) touch.view;
      ...
      [self bringSubviewToFront:cardView];
      ...
   }
}

Unfortunately, the card’s z-order remains unchanged during the drag. In the images below, I am dragging the King. Notice how it is correctly on top the Nine in the left image, but is incorrectly under the Two (under the entire stack actually) in the right image:

enter image description here enter image description here

I also tried alter the layer.zPosition property as well to no avail.
How can I bring the card view to the front during the drag? I am mystified.

  • 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-01T12:43:58+00:00Added an answer on June 1, 2026 at 12:43 pm

    Confirmed. bringSubviewToFront: causes layoutSubview to be invoked. Since my version of layoutSubviews sets the z-orders on all the views, this was undoing the z-order I was setting in the touchesBegan:withEvent code above. Apple should mention this side effect in the bringSubviewToFront documentation.

    Instead of using a UIView subclass, I created a CALayer subclass named CardLayer. I handle the touch in my KlondikeView subclass as listed below. topZPosition is an instance var that tracks the highest zPosition of all cards. Note that modifying the zPosition is usually animated — I turn this off in the code below:

    -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
       UITouch *touch = [touches anyObject];
       CGPoint touchPoint = [touch locationInView:self];
       CGPoint hitTestPoint = [self.layer convertPoint:touchPoint
                                               toLayer:self.layer.superlayer];
       CALayer *layer = [self.layer hitTest:hitTestPoint];
    
       if (layer == nil) return;
    
       if ([layer.name isEqual:@"card"]) {
         CardLayer *cardLayer = (CardLayer*) layer;
         Card *card = cardLayer.card;
    
         if ([self.solitaire isCardFaceUp:card]) {
            //...                                                                                                            
            [CATransaction begin]; // disable animation of z change                                                                  
            [CATransaction setValue:(id)kCFBooleanTrue
                             forKey:kCATransactionDisableActions];              
            cardLayer.zPosition = topZPosition++; // bring to highest z
    
            // ... if card fan, bring whole fan to top
    
            [CATransaction commit];
            //...                                                                                                            
         }
         // ...                                                                                                             
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a simple game for an assignment that would ideally run both on
Web-development novice here. I want to try implementing a simple web site that uses
I am implementing a simple recommendation system for a collection of user created components.
I am implementing a simple RoR webpage that collect emails from visitors and store
I'm implementing simple drag-and-drop functionality in my app, and I would like to know
I'm implementing a simple eclipse notification plugin that is supposed to change an icon
I'm implementing a simple game in Javascript, and am interested in having an online
I am implementing a simple portal using jsp and struts, the user full fill
I'm implementing a simple web-page, in that page, I have multiple div objects, what
I am implementing a simple timer that throws a RT signal upon expiration. What

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.