我正在尝试将UIView上的边框与drawRect中绘制的线组合在一起.我使用相同的宽度.但问题是有时候绘制的线条的宽度对于两者都是相同的,有时则不一样 - 这甚至会随着设备方向的变化而变化!但即使不改变设备方向,它通常仍然不是相同的宽度.
边框绘制为:
view.layer.borderColor = [UIColor blackColor].CGColor;
view.layer.borderWidth = 1.0f;
Run Code Online (Sandbox Code Playgroud)
在该视图上方是另一个视图,它是UIView的子类.两个视图具有相同的宽度,第二个视图覆盖上面的视图顶部.覆盖视图使用drawRect中的以下代码在左侧绘制一条线,该线应该与其下方视图的边框完美对齐:
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat x = self.bounds.origin.x;
CGFloat y = self.bounds.origin.y;
CGFloat width = self.bounds.size.width;
CGFloat height = self.bounds.size.height;
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
// Left line
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x, height);
CGContextStrokePath(context);
// Right line
CGContextMoveToPoint(context, width - 1.0f, y);
CGContextAddLineToPoint(context, width - 1.0f, height);
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
任何想法如何实现这一目标?现在,即使宽度始终为1.0f,如果两条线都以相同的可见宽度绘制,也只是巧合.
目标是最终得到一些看起来像底部圆角但顶部通常边缘的视图.这就是我这样做的原因.第一个视图具有圆角,其上方的第二个视图在宽度上匹配但覆盖顶部,因此顶部的圆角不可见.
屏幕截图:

横向截图:

黄色视图位于白色视图上方.由于view.layer.borderWidth = 1.0f,绘制了白色视图的黑色线条.黄色视图左侧和右侧的黑线用drawRect绘制,上面的代码.方向更改会触发重绘,但绘图代码本身保持不变.两张截图均来自带视网膜显示屏的iPhone(iPhone 4S).
据我所知,所有值都是"整数":
x: 0.000000, y: 0.000000
width: 264.000000, height: 10.000000
frame.origin.x: 33.000000, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用libgit2来首先克隆一个裸存储库,然后使用来自github源的更改来更新它.克隆工作正常:
git_repository *_repository
git_clone_bare(&_repository, REPOSITORY_URL, path, &transferProgressCallback, NULL);
git_repository_free(_repository);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试从源libgit2更新存储库时,总是再次下载整个存储库.它只是不提取更改.我正在使用此代码:
git_remote *remote;
git_repository *_repository;
git_repository_open(&_repository, path);
git_remote_load(&remote, _repository, "origin");
git_remote_connect(remote, GIT_DIR_FETCH);
git_remote_download(remote, &transferProgressCallback, NULL);
git_remote_disconnect(remote);
git_remote_update_tips(remote);
git_remote_free(remote);
Run Code Online (Sandbox Code Playgroud)
(我删除了错误处理.)我使用这样的回调来报告进度:
void transferProgressCallback(const git_transfer_progress *stats, void *payload) {
float receivedMegaBytes = (float)stats->received_bytes/(1024*1024.0);
float progress = ((float)stats->received_objects / (float)stats->total_objects) * 100.0;
printf("Loading: %.1f (%.1f)\n", progress, receivedMegaBytes);
}
Run Code Online (Sandbox Code Playgroud)
根据回调,下载了所有内容(与git_clone_bare相同的字节数).我一定是错过了什么或做错了什么,对吧?但我没有看到哪里.我想要的只是代码仅提取更改(即本地不存在的内容).但相反,它不断获取整个存储库.
拜托,这可能是什么问题?非常感谢你提前!