【问题标题】:How do I integrate PaintCode snippets into XCode (iOS 6)如何将 PaintCode 片段集成到 XCode (iOS 6)
【发布时间】:2013-11-23 21:19:23
【问题描述】:

我需要将 PaintCode sn-ps 集成到 XCode 中,但到目前为止我在模拟器中没有看到结果,这是一个矩形的 sn-p:

// Rounded Rectangle Drawing
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3];
[[UIColor whiteColor] setFill];
[roundedRectanglePath fill];
[[UIColor blackColor] setStroke];
[roundedRectanglePath setLineWidth: 10];
[roundedRectanglePath stroke];

我在实现文件中使用了一个 void 函数:

- (void) drawRect: (CGRect)rect
{
    // snippet goes here
}

【问题讨论】:

  • 这是在某些 UIView 子类中完成的吗?视图是屏幕视图层次结构的一部分吗?
  • 不在子类中,在视图控制器中,但我尝试对其进行子类化,仍然不起作用。
  • drawRect: 在视图中工作,而不是在视图控制器中。
  • 但是我尝试将它子类​​化到 UIView,它仍然没有工作......
  • 上面没有提到 UIView 或显示你正在做什么以将视图放到屏幕上。每次您提到“视图控制器”时,我都会更加怀疑您将代码放在错误的位置。 :)

标签: objective-c ios6.1


【解决方案1】:

PaintCode 生成的代码需要包装在 UIView 子类的 drawRect: 方法中。

您还应该:

在您似乎正在使用的UIViewController 中导入您的子类头文件,即#import "OnScreenGraphics.h"

创建一个类的实例,例如

// add a subview to fill the entire view; your requirements
// may be different, of course
OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
[[self view] addSubview:fancyView];

编辑2013-11-24 07-33-25

#import <UIKit/UIKit.h>

@interface OnScreenGraphics : UIView

@end

#import "OnScreenGraphics.h"

@implementation OnScreenGraphics

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if( !self ) return nil;

    self.backgroundColor = [UIColor clearColor];

    return self;
}

- (void)drawRect:(CGRect)rect{
    UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3];
    [[UIColor clearColor] setFill];
    [roundedRectanglePath fill];
    [[UIColor blackColor] setStroke];
    [roundedRectanglePath setLineWidth: 10];
    [roundedRectanglePath stroke];
}

@end

And in your view controller implementation:

@implementation AKDMoreDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
    [[self view] addSubview:fancyView];

}

// etc.

@end

当我在测试项目中执行此操作时,我看到:

现在,所有这些都说明了,您的突出显示子视图大概覆盖了您希望突出显示的按钮;因此,即使您可以看到按钮,它也可能不会响应触摸事件,除非您在该视图上禁用用户交互fancyView.userInteractionEnabled = NO;

【讨论】:

  • 感谢@NSBum 现在我看到了矩形,但我看不到我的应用程序的其余部分,即想法是在顶部绘制矩形。我尝试使用 initWithFrame:CGRectMake(45.5, 89.5, 232, 273) 但这只是给了我一个黑色矩形。
  • 也许您可以描述或说明您希望视图的外观。
  • 我希望视图有一个透明填充(我想是 clearColor)矩形,例如在预先存在的按钮(使用 Interface Builder 制作的按钮)之上,基本上只是为了突出显示它。
  • 可能[[UIColor clearColor] setFill]; 也将您的自定义视图的backgroundColor 设置为清除。
  • 我都做了 clearColor [[UIColor clearColor] setFill];和 backgroundColor fancyView.layer.backgroundColor = [[UIColor clearColor] CGColor];但它仍然只是显示黑屏。
【解决方案2】:

如果你只想快速显示 PaintCode sn-ps 试试

https://github.com/kaishin/Verbena

渲染到 UIImage 的内联核心图形 - 对 PaintCode 很有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多