我正在尝试制作一个绘图应用程序。我有一个自定义 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。一个是黑色、半透明且“全屏”(“overlayView”),另一个位于顶部,较小且可调整大小(“cropView”)。这几乎是一个裁剪视图设置,我想“调暗”未裁剪的底层图像区域。
我的问题是:我该怎么做?我确信我的方法应该使用 CALayers 和掩模,但无论我尝试什么,我都无法理解逻辑。
这就是我现在所拥有的:
这就是我希望它看起来像的样子:
我如何在 Swift 中实现这个结果?
我见过一些应用程序的内容区域很小,但给你提供了很好的“iOS”效果,允许你弹跳/下拉/滚动视图。基本上与使用 UITableView 的效果完全相同。
当视图中的内容超出手机大小时,我可以使用 UIView/ScrollView 获得这种效果,但是如何始终“启用”它?
我有这样的资产目录
我如何获取取决于组件(文件夹)的图像?我喜欢使用它本来的样子
let image = UIImage(named:"ComponentA/Background")
Run Code Online (Sandbox Code Playgroud)
但这不起作用
我的代码:
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 不起作用。
ios ×5
swift ×3
objective-c ×2
calayer ×1
cgcontext ×1
mask ×1
nsoperation ×1
uiscrollview ×1
uiview ×1