- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个模态视图,我想在其中显示计算结果。为了使它看起来像 iOS7,我想要一个带有模糊背景的弹出 View 的有色背景。
我设法使用来自苹果的“UIImage+ImageEffects .h/m”文件让那个东西工作。
这是模态视图的 viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
/* How it works
self.image is a screenshot of the VC presenting the modal view
1- we set the background as the screenshot of the previous viewControler
2- we hide the popup view
3- we set the background of the popup as a blured snapshot of its container view (self.view)
4- we unhide the popup view and set its radius
5- we create a tinted version of the background image (what we got from the previous view controller
6- we set the background of self.view to the tinted version
*/
// *** 1 ***
self.view.backgroundColor=[UIColor colorWithPatternImage:self.image];
// *** 2 ***
self.containerView.hidden=YES;
// *** 3 ***
UIImage *pepe=[self bluredImageFromView:self.containerView withBackground:self.view withBackgroundTintColor:[UIColor colorWithWhite:1 alpha:0.75]];
self.containerView.backgroundColor=[UIColor colorWithPatternImage:pepe];
// *** 4 ***
self.containerView.hidden=NO;
self.containerView.layer.cornerRadius=4.5f;
// *** 5 ***
UIImage *tintedBackground =[self.image applyBlurWithRadius:0
tintColor:[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:0.35]
saturationDeltaFactor:1.8
maskImage:nil];
// *** 6 ***
self.view.backgroundColor=[UIColor colorWithPatternImage:tintedBackground];
}
它在模拟器上运行良好,但是当我在我的 iPhone (4S) 上尝试时,当显示模态视图时,我遇到了黑屏。没有错误,没有来自控制台的提示,什么都没有。
有什么想法吗?
编辑
我添加代码:
if (!self.image) NSLog (@"self.image is empty");
在viewDidLoad的最开始
似乎在模拟器上 self.image 不是 nil 而在设备上是。我试图在父 VC 上从 prepareForSegue 实例化 self.image 但没有用。
最佳答案
我不知道你的 bluredImageFromView
是如何工作的,但是模拟器和实际的 iOS 设备之间存在安全(沙盒)差异(特别是 resizableSnapshotViewFromRect:
和drawViewHierarchyInRect:
) 这可能解释了它为什么有效(但在设备上不起作用。)
看看这个 thread在 raywenderlich.com 上,有人从 Apple Developer 技术支持那里得到了建议。此示例代码显然来自 Apple。
- (IBAction)doBlurAndCrop:(id)sender {
UIImage *snapshotImage;
/* draw the image of all the views below our view */
UIGraphicsBeginImageContextWithOptions(self.sourceImageView.bounds.size, NO, 0);
BOOL successfulDrawHierarchy = [self.sourceImageView drawViewHierarchyInRect:self.sourceImageView.bounds afterScreenUpdates:YES];
if ( successfulDrawHierarchy ) {
snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
} else {
NSLog(@"drawViewHierarchyInRect:afterScreenUpdates: failed - there's nothing to draw...");
}
UIGraphicsEndImageContext();
if ( successfulDrawHierarchy ) {
/* calculate the coordinates of the rectangle we're interested in within the returned image */
CGRect cropRect = CGRectOffset(self.targetImageView.frame, - self.sourceImageView.frame.origin.x, - self.sourceImageView.frame.origin.y);
/* draw the cropped section with a clipping region */
UIGraphicsBeginImageContextWithOptions(cropRect.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height));
CGRect targetRectangeForCrop = CGRectMake(-cropRect.origin.x, -cropRect.origin.y, snapshotImage.size.width, snapshotImage.size.height);
[snapshotImage drawInRect:targetRectangeForCrop];
UIImage *croppedSnapshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/* apply a special effect to the resulting image and copy it into place on screen */
UIColor *tintColor = [UIColor colorWithWhite:1.0 alpha:0.3];
self.targetImageView.image = [croppedSnapshotImage applyBlurWithRadius:5 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}
}
关于ios - UIImage+ImageEffects 在设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22897470/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!