小编Wai*_*ain的帖子

Swift - 使用 CGContext 用手指绘图

我正在尝试制作一个绘图应用程序。我有一个自定义 UIView:

class DrawView: UIView {

var touch : UITouch!
var lastPoint : CGPoint!
var currentPoint : CGPoint!

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    touch = touches.first as! UITouch
    lastPoint = touch.locationInView(self)
    println(lastPoint)
}

override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
    touch = touches.first as! UITouch
    currentPoint = touch.locationInView(self)

    self.setNeedsDisplay()

    lastPoint = currentPoint
}

override func drawRect(rect: CGRect) {
    var context = UIGraphicsGetCurrentContext()
    CGContextSetLineWidth(context, 5)
    CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
    CGContextSetLineCap(context, kCGLineCapRound)

    CGContextBeginPath(context)

    if lastPoint != nil {
        CGContextMoveToPoint(context, lastPoint.x, …
Run Code Online (Sandbox Code Playgroud)

uiview cgcontext ios swift

5
推荐指数
1
解决办法
4262
查看次数

在 Swift 中从另一个 UIView 中减去 UIView

我确信这是一件非常简单的事情,但我似乎无法理解其中的逻辑。

我有两个 UIView。一个是黑色、半透明且“全屏”(“overlayView”),另一个位于顶部,较小且可调整大小(“cropView”)。这几乎是一个裁剪视图设置,我想“调暗”未裁剪的底层图像区域。

我的问题是:我该怎么做?我确信我的方法应该使用 CALayers 和掩模,但无论我尝试什么,我都无法理解逻辑。

这就是我现在所拥有的:

这就是它的样子

这就是我希望它看起来像的样子:

这就是我想要的样子

我如何在 Swift 中实现这个结果?

mask calayer ios swift

4
推荐指数
1
解决办法
2031
查看次数

iOS ScrollView/Bounce 与非滚动内容

我见过一些应用程序的内容区域很小,但给你提供了很好的“iOS”效果,允许你弹跳/下拉/滚动视图。基本上与使用 UITableView 的效果完全相同。

当视图中的内容超出手机大小时,我可以使用 UIView/ScrollView 获得这种效果,但是如何始终“启用”它?

uiscrollview ios

3
推荐指数
1
解决办法
1112
查看次数

如何通过文件夹ios从资产中获取图像

我有这样的资产目录

  • 资产
    • 组件A - 文件夹
      • 背景图
    • 组件B-文件夹
      • 背景图

我如何获取取决于组件(文件夹)的图像?我喜欢使用它本来的样子

let image = UIImage(named:"ComponentA/Background")
Run Code Online (Sandbox Code Playgroud)

但这不起作用

objective-c ios swift

3
推荐指数
1
解决办法
3998
查看次数

当 viewWillDisappear 时 NSOperationQueue cancelAllOperations 不起作用

我的代码:

NSOperationQueue *queue;

-(void)viewDidLoad
{
    queue = [NSOperationQueue new];
    NSOperation* loadImgOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(refresh) object:nil];
    [queue addOperation:loadImgOp];

}

-(void)refresh
{
   [self operationFirst];         
   [self operationSecond];
   ... 
   [self operationFive];
   dispatch_async(dispatch_get_main_queue(), ^{
      [self.tableView reloadData];
   });

}

- (void)viewWillDisappear:(BOOL)animated {
   [super viewWillDisappear:animated];
   [queue cancelAllOperations];     
}
Run Code Online (Sandbox Code Playgroud)

当我调用 new ViewController 时,-(void)refresh 继续工作。cancelAllOperations 不起作用。

objective-c nsoperation nsoperationqueue ios

2
推荐指数
1
解决办法
2018
查看次数