标签:begin dde app 获取 graph and nil sel 隐藏
#import "UINavigationBar+ChangeColor.h"
@implementation UINavigationBar (ChangeColor)
- (void)start{
UIImageView *shawImage = [self findNavLineImageOn:self];
shawImage.hidden = YES;
self.translucent = YES;
}
- (void)reset{
UIImageView *shawImage = [self findNavLineImageOn:self];
shawImage.hidden = NO;
[self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.translucent = NO;
}
- (void)changeColor:(UIColor *)color withScrollView:(UIScrollView *)scrollView andValud:(CGFloat)value{
if (scrollView.contentOffset.y < 0) {
//下拉时导航隐藏
self.hidden = YES;
}else{
self.hidden = NO;
//计算透明度
CGFloat alpha = scrollView.contentOffset.y /value > 1.0f ? 1 : scrollView.contentOffset.y/value;
//设置颜色改为图片
UIImage *image = [self imageWithColor:[color colorWithAlphaComponent:alpha]];
[self setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
self.translucent = alpha >=1.0f ? NO : YES;
}
}
- (UIImageView *)findNavLineImageOn:(UIView *)imageView{
if ([imageView isKindOfClass:[UIImageView class]] && imageView.frame.size.height <=1.0) {
return (UIImageView *)imageView;
}
for (UIView *subViews in imageView.subviews) {
UIImageView *imageView = [self findNavLineImageOn:subViews];
if (imageView) {
return imageView;
}
}
return nil;
}
#pragma mark - Color To Image
- (UIImage *)imageWithColor:(UIColor *)color {
//创建1像素区域并开始图片绘图
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
//创建画板并填充颜色和区域
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
//从画板上获取图片并关闭图片绘图
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
标签:begin dde app 获取 graph and nil sel 隐藏
原文地址:https://www.cnblogs.com/TheYouth/p/9300318.html