나는 정말 간단해야 할 일을하려고합니다. 내 견해 중 하나에 그라디언트를 추가하고 싶습니다. self.view에는 추가 할 수 있지만 viewWithGradient에는 추가 할 수 없습니다. 여기 코드는 다음과 같습니다iPhone 레이어 혼란
CAGradientLayer *gradient = [CAGradientLayer layer];
UIColor *colorFirst = [UIColor colorWithWhite:0.10 alpha:0.15];
UIColor *colorLast = [UIColor colorWithWhite:0.535 alpha:0.8];
NSArray *colors = [NSArray arrayWithObjects:(id)colorFirst.CGColor, colorLast.CGColor, nil];
gradient.colors = colors;
NSNumber *stopFirst = [NSNumber numberWithFloat:0.00];
NSNumber *stopLast = [NSNumber numberWithFloat:1.00];
NSArray *locations = [NSArray arrayWithObjects:stopFirst, stopLast, nil];
gradient.locations = locations;
gradient.frame = CGRectMake(0.0, viewWithGradient.frame.origin.y, viewWithGradient.frame.size.width, height_of_gradient);
[self.view.layer addSublayer:gradient]; // this works. I get a nice gradient at
// the bottom of the view, where I want it,
// but I need the gradient further down in
// my view hierarchy.
// [viewWithGradient.layer addSublayer:gradient]; // this doesn't. There
// is no visually noticeable change
// if this is uncommented and the
// above line is.
viewWithGradient은의 ViewController (self.view) 안에 내 주 화면 안에 작은이다. 이 viewWithGradient에는 다른 뷰가 하나만 있습니다. UILabel은 viewWithGradient 영역의 절반 밖에 차지하지 않습니다. 그것은 배경이 투명하지만 레이블이 텍스트를 흰색으로 그립니다. 나는 그라디언트를 UILabel 위의 self.view가 아닌 UILabel 아래에 두어야합니다.
현재 내 프레임/경계가 그라디언트를 화면에 표시하지 않을 수 있습니다. 아무도 내가 빠진 것을 볼 수 있습니까? 이것은 CALayer 사용법 중 가장 단순한 것으로 보이며, 너무 많은 시간을 소비했습니다.
viewWithGradient의 배경색을 사용하여 해킹 해 봤니? 어쩌면 viewWithGradient의 불투명 한 속성을 NO로 변경 했을까? ... 그냥 약간의 제안. – wkw
불투명도는 이미 NO로 설정되어 있으며 배경은 clearColor로 설정되어 있습니다. 나는 혼란 스럽다. – mahboudz