tru*_*duc 6 objective-c ios swift uialertcontroller
我希望有一个UIActionSheet自定义,UIAlertAction但似乎自定义UIAlertAction不合法.
UIAlertController类旨在按原样使用,不支持子类化.此类的视图层次结构是私有的,不得修改.
所以我正在尝试创建一个看起来完全一样的视图UIActionSheet.通过使用Debug View Hierarchy,我可以知道Apple如何应用层次结构,约束,颜色UIActionSheet来完成他们所做的事情.
我可以创建除了UIActionSheet背景之外的所有东西.这是一个包含非透明视图和视图的视图UIVisualEffectView.
该UIVisualEffectView重叠不透明的看法,但不知何故UIVisualEffectView仍然有效.
UIVisualEffectView下面有一个不透明的时候怎么还能工作呢?如果有可能,我怎么能做这样的事情?
注意:背景UIActionSheet不仅仅是一个UIVisualEffectView.请不要给出这样的答案.
下面的视图UIVisualEffectView(问题中带有红色箭头的视图)包含一个图层,该图层将 CAFilter“overlayBlendMode”(私有类)设置为合成过滤器。它应用在其后面的层上。在下面的屏幕截图中,我将 _UIDimmingKnockoutBackdropView 的背景颜色更改为绿色,并在其上应用过滤器。
私有方法
要创建相同的效果,您需要在下面放置一个白色不透明视图UIVisualEffectView并对其应用 CAFilter:
CAFilter *filter = [CAFilter filterWithName:@"overlayBlendMode"];
[[contentView layer] setCompositingFilter:filter];
Run Code Online (Sandbox Code Playgroud)
由于 CAFilter 是私有的,我们需要它的标头:
#import <Foundation/Foundation.h>
@interface CAFilter : NSObject <NSCoding, NSCopying, NSMutableCopying> {
void * _attr;
void * _cache;
unsigned int _flags;
NSString * _name;
unsigned int _type;
}
@property BOOL cachesInputImage;
@property (getter=isEnabled) BOOL enabled;
@property (copy) NSString *name;
@property (readonly) NSString *type;
// Image: /System/Library/Frameworks/QuartzCore.framework/QuartzCore
+ (void)CAMLParserStartElement:(id)arg1;
+ (BOOL)automaticallyNotifiesObserversForKey:(id)arg1;
+ (id)filterTypes;
+ (id)filterWithName:(id)arg1;
+ (id)filterWithType:(id)arg1;
- (void)CAMLParser:(id)arg1 setValue:(id)arg2 forKey:(id)arg3;
- (id)CAMLTypeForKey:(id)arg1;
- (struct Object { int (**x1)(); struct Atomic { struct { int x_1_2_1; } x_2_1_1; } x2; }*)CA_copyRenderValue;
- (BOOL)cachesInputImage;
- (id)copyWithZone:(struct _NSZone { }*)arg1;
- (void)dealloc;
- (BOOL)enabled;
- (void)encodeWithCAMLWriter:(id)arg1;
- (void)encodeWithCoder:(id)arg1;
- (id)initWithCoder:(id)arg1;
- (id)initWithName:(id)arg1;
- (id)initWithType:(id)arg1;
- (BOOL)isEnabled;
- (id)mutableCopyWithZone:(struct _NSZone { }*)arg1;
- (id)name;
- (void)setCachesInputImage:(BOOL)arg1;
- (void)setDefaults;
- (void)setEnabled:(BOOL)arg1;
- (void)setName:(id)arg1;
- (void)setValue:(id)arg1 forKey:(id)arg2;
- (id)type;
- (id)valueForKey:(id)arg1;
// Image: /System/Library/PrivateFrameworks/PhotosUICore.framework/PhotosUICore
+ (id)px_filterWithPXCompositingFilterType:(int)arg1;
@end
Run Code Online (Sandbox Code Playgroud)
解决方法
作为解决方法,您可以在背景上创建视图的图像和白色视图的图像,然后应用叠加混合模式。这会产生与使用私有类相当的结果。
例子:
UIImage *image = [self imageForView:contentView];
UIView *superview = [contentView superview];
[contentView setHidden:YES];
UIImage *backgroundImage = [self imageForView:superview];
CGImageRef imageRef = CGImageCreateWithImageInRect([backgroundImage CGImage], [contentView frame]);
backgroundImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
[contentView setHidden:NO];
CIFilter *filter = [CIFilter filterWithName:@"CIOverlayBlendMode"];
[filter setValue:[backgroundImage CIImage] forKey:kCIInputImageKey];
[filter setValue:[image CIImage] forKey:kCIInputBackgroundImageKey];
[contentView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageWithCIImage:[filter outputImage]]]];
}
- (UIImage *)imageForView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions([view bounds].size, [view isOpaque], 1.0);
[[view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
607 次 |
| 最近记录: |