【发布时间】:2012-03-02 04:41:49
【问题描述】:
正如你们中的一些人可能已经注意到的那样,大多数(如果不是全部)系统应用程序的屏幕显示为圆角。我的意思是,设备屏幕的四个角看起来是圆的。
但是,大多数第三方应用程序都没有(角是 90º),但我已经看到一些这样做了,例如 Facebook Messenger。很多其他的都有这个效果,但只是在闪屏上(可能只是对 default.png 图像文件的修改)
有没有实现这个效果的属性?
【问题讨论】:
正如你们中的一些人可能已经注意到的那样,大多数(如果不是全部)系统应用程序的屏幕显示为圆角。我的意思是,设备屏幕的四个角看起来是圆的。
但是,大多数第三方应用程序都没有(角是 90º),但我已经看到一些这样做了,例如 Facebook Messenger。很多其他的都有这个效果,但只是在闪屏上(可能只是对 default.png 图像文件的修改)
有没有实现这个效果的属性?
【问题讨论】:
如果您想要整个应用程序上的圆角,并且不必使用您想要的每个不同的视图控制器显式地重新创建它们,请在 AppDelegate 中调用它:(didFinishLaunching 方法)
[self.window.layer setCornerRadius:20.0];
[self.window.layer setMasksToBounds:YES];
self.window.layer.opaque = NO;
别忘了:
#import <QuartzCore/QuartzCore.h>
这种方式更好,因为它在 WINDOW 而不是 VIEW 上创建动画。因此,您可以将 UI 的其余部分设计为 90° 角,并且它们会自动变圆。调用一次要容易得多。
光栅化图层也可能更好地提高性能,尤其是在滞后的情况下:
[self.window.layer setShouldRasterize:YES];
[self.window.layer setRasterizationScale:[UIScreen mainScreen].scale];
以上内容将强制动画/图形更改“像图像一样”,而不会使 UI 过于沉重。性能将根据 Retina 或 Non-Retina Screens 提高和光栅化。 (这是 [UIScreen] 调用,因为“.scale”对于视网膜返回 2.0,对于非视网膜返回 1.0。非常非常简单。
希望这有帮助!打勾,如果是这样,我会回来看看! :)
【讨论】:
以下将圆角视图。你可以把它放在viewDidLoad中:
#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 7;
【讨论】:
// Import QuartzCore.h at the top of the file
#import <QuartzCore/QuartzCore.h>
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 20.0;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);
查看Introduction to CALayers Tutorial。您将获得良好的开端。
【讨论】:
@PsycoDad:对@cocotouch 的回答的这一补充修复了屏幕的顶部
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window.layer.frame = self.window.layer.bounds =
CGRectMake(0,
statusBarHeight,
screenBounds.size.width,
screenBounds.size.height - statusBarHeight);
【讨论】: