Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Confirmed. <code>bringSubviewToFront:</code> causes <code>layoutSubview</code> to be invoked. Since my version of <code>layoutSubviews</code> sets the z-orders on all the views, this was undoing the z-order I was setting in the <code>touchesBegan:withEvent</code> code above. Apple should mention this side effect in the <code>bringSubviewToFront</code> documentation.</p> <p>Instead of using a <code>UIView</code> subclass, I created a <code>CALayer</code> subclass named <code>CardLayer</code>. I handle the touch in my <code>KlondikeView</code> subclass as listed below. topZPosition is an instance var that tracks the highest zPosition of all cards. Note that modifying the <code>zPosition</code> is usually animated -- I turn this off in the code below:</p> <pre><code>-(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]; //... } // ... } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload