タイル パターンを表示するカスタム UIImageView クラスを設計しました。このクラスは、ストーリーボードで使用するように設計されています。パターンは、awakeFromNib プロトコルの CALayer でランタイム パラメータを使用して構築されます。
アニメーションのセグエを使用しようとするまで、すべて正常に動作します。シミュレーターでは完全に動作しますが、iPad で実行するとレイヤーが黒くなります。アニメーションを無効にすると、すべてが機能します。
何か案は?
コードは次のとおりです。
_hasRoundedCorners と _textureImage はランタイム パラメータです。
- (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];
}
}
更新:さらにテストを行いました。一部のセグエ アニメーションだけが問題を引き起こします。Cover Vertical と Cross Dissolve はこの動作を示します。Flip Horizontal と Partial Curl は正常に機能します。
また、機能を追加しました (以下を参照)。このクラスはグラデーションまたはパターンを表示し、オプションのドロップ シャドウも表示します。プロパティ値は、デザイン時にストーリーボードに設定されます。
@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;
- (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];
}
}
}