Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom UIImageView works in iOS simulator but is black on iPad when using animated segue
    primarykey
    data
    text
    <p>I've designed a custom UIImageView class that displays a tile pattern. The class is designed to be used in a storyboard. The pattern is built using runtime parameters on a CALayer in the awakeFromNib protocol.</p> <p>Everything works fine until I try to use an animated segue. It works perfectly on the simulator but when I run it on the iPad, the layer is black. If I disable the animation everything works.</p> <p>Any ideas?</p> <p>Here is the code:</p> <p>_hasRoundedCorners and _textureImage are runtime parameters</p> <pre><code>- (void) awakeFromNib { [super awakeFromNib]; CALayer *textureLayer = [CALayer layer]; [textureLayer setFrame:[self bounds]]; if (_hasRoundedCorners) { [textureLayer setCornerRadius:6.0f]; } UIColor *mycolor=[UIColor colorWithPatternImage:[UIImage imageNamed:_textureImage]]; [textureLayer setBackgroundColor:mycolor.CGColor]; [[self layer] addSublayer:textureLayer]; } } </code></pre> <p>UPDATE: I did further testing. Only some segue animations cause the problem. Cover Vertical and Cross Dissolve exhibit the behavior. Flip Horizontal and Partial Curl work fine.</p> <p>I also have added additional functionality (see below). The class now will display a gradient or a pattern as well as having an optional drop shadow. Property values are set at design time in the storyboard.</p> <pre><code>@property (assign) BOOL hasDropShadow; @property (assign) BOOL hasRoundedCorners; @property (assign) BOOL hasGradient; @property (strong, nonatomic) UIColor *highColor; @property (strong, nonatomic) UIColor *lowColor; @property (strong, nonatomic) NSString *textureImage; </code></pre> <hr> <pre><code>- (void) awakeFromNib { [super awakeFromNib]; //turning off bounds clipping allows the shadow to extend beyond the rect of the view if (_hasDropShadow) { [self setClipsToBounds:NO]; } CALayer * roundRect = [CALayer layer]; [roundRect setFrame:[self bounds]]; if (_hasRoundedCorners) { [roundRect setCornerRadius:6.0f]; [roundRect setMasksToBounds:YES]; } if(_hasGradient){ //the default colors for the gradient. highColor is at the top, lowColor as at the bottom if (!_highColor){ _highColor = [UIColor lightGrayColor]; } if (!_lowColor){ _lowColor = [UIColor darkGrayColor]; } CAGradientLayer * gradient = [CAGradientLayer layer]; [gradient setFrame:[self bounds]]; [gradient setColors:[NSArray arrayWithObjects:(id)[_highColor CGColor], (id)[_lowColor CGColor], nil]]; [roundRect addSublayer:gradient]; } //add the rounded rect layer underneath all other layers of the view [[self layer] insertSublayer:roundRect atIndex:0]; //set the shadow on the view's layer if (_hasDropShadow) { [[self layer] setShadowColor:[[UIColor blackColor] CGColor]]; [[self layer] setShadowOffset:CGSizeMake(0, 6)]; [[self layer] setShadowOpacity:1.0]; [[self layer] setShadowRadius:10.0]; } if(!_hasGradient){ //set up the texture layer CALayer *textureLayer = [CALayer layer]; [textureLayer setFrame:[self bounds]]; if (_hasRoundedCorners) { [textureLayer setCornerRadius:6.0f]; } UIColor *mycolor=[UIColor colorWithPatternImage:[UIImage imageNamed:_textureImage]]; if (mycolor) { [textureLayer setBackgroundColor:mycolor.CGColor]; [[self layer] addSublayer:textureLayer]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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