ios - 在上下文中绘制 View ,这是什么意思?

标签 ios objective-c uiview draw cgcontext

我的 View 如下所示:

_myController = [[MSCustomViewController alloc] init];
    _myController.doc = (AWDOC *)_currentDocumentViewController.activeFile.document;
    _myController.view.backgroundColor = [UIColor colorWithHue:0.7/3.3 saturation:0.2 brightness:1.0 alpha:1.0];
    [self.view insertSubview:_myController.view aboveSubview:_myController];
    CGSize size = [_myController.view sizeThatFits:CGSizeZero];
    if(size.height < _myController.frame.size.height)
        size.height = _myController.frame.size.height;
    CGRect myFrame = CGRectMake(0., CGRectGetMinY(_currentDocumentViewController.view.bounds) + (CGRectGetHeight(_currentDocumentViewController.view.bounds) - size.height) / 2., size.width, size.height);
    _myController.view.frame = myFrame;
    CGRect buttonFrame = CGRectMake(CGRectGetMaxX(myFrame), CGRectGetMinY(myFrame), myButton.frame.size.width, CGRectGetHeight(myFrame));
    _myButton.frame = buttonFrame;
    [_myButton setTitle:@"<" forState:UIControlStateNormal];

“使用上下文绘制此 View 或绘制”是什么意思?

最佳答案

将默认 UIView 添加到您的 View Controller 以保存内置 View ,如 UIButton、UIImageView、UILabel。您添加为:

UIView *view = [[[UIView alloc] initwithFrame:CGRectMake(..)];

现在,要在 UIView 中制作自定义绘图,您必须定义自己的 View (通过创建继承 UIView 的新类来实现)。假设您制作的类(class)是 StandardView 类(class)。 当您继承 UIView 时,drawRect: 是在您的 View Controller 中初始化此 uiview 时调用的默认方法:

Standardview * stndView = [[Standardview alloc]initWithFrame:CGRectMake(0, 0, 320, 300];

因此,您可以将所有绘图内容放入 drawRect: 方法中。通常,您使用 OpenGL/ES 或 CoreGraphics 进行绘图。在使用 coregraphics 函数时,您可以为 coregraphics 的每个函数指定上下文。该上下文意味着您的图形目标。

关于ios - 在上下文中绘制 View ,这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24062699/

相关文章:

ios - 绕过 "Sign in with Apple"

ios - 如何获取音频 block 以在核心音频或 AVFoundation 中进行分析

ios - 当应用程序从 ios7 中的应用程序切换器中被杀死时,静默推送不起作用

ios - 在 xcode 中使用 GZIP 压缩 CSV 文件

iphone - UIView 动画完成后执行代码?

ios - 如何裁剪带有重复半圆的 UIView?

ios - 如何为 iOS 交叉编译 clang/llvm?

ios - 如何从多个 View Controller 推送到一个 View Controller 对象

objective-c - 为什么这些字符串不相等?

ios - 为特征改变用户定义的运行时属性