小编Vas*_*rov的帖子

在iOS中绘制半透​​明矩形

我一直在寻找答案,并试图自己解决,但我不能,我认为这是最好的问题.所以我想要完成一些简单的事情,但我找不到这样做的方法.我想我在概念层面上缺少一些东西.这就是我尝试在我的类中创建半透明矩形的方法,该矩形是UIView的子类:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    //this should be white color with 0.7 opacity right
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.7);
    CGContextFillRect(context, self.bounds);
}
Run Code Online (Sandbox Code Playgroud)

好的,这只会使颜色变灰.我也试过这个但结果相同:CGContextSetRGBFillColor(context,1.0,1.0,1.0,1.0);
CGContextSetAlpha(context,0.7);

另一个尝试:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
    CGContextFillRect(context, self.bounds);

    self.alpha = 0.7;
}
Run Code Online (Sandbox Code Playgroud)

瞧!我解决了 但不完全是.我想在上下文中绘制一个半透明的矩形,而不是让整个视图透明.然后例如添加另一个完全不透明的矩形.很想听听你的想法.谢谢.

core-graphics objective-c ios

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

在 iOS 13 中将 UIImagePickerController 导航栏设置为不透明

我正在展示一个UIImagePickerController选择图像。我的代码很简单:

private lazy var imagePicker: UIImagePickerController = {
    let picker = UIImagePickerController()
    picker.navigationBar.isTranslucent = false
    return picker
}()

func presentPicker() {
    imagePicker.sourceType = .photoLibrary
    imagePicker.modalPresentationStyle = .fullScreen        
    present(self.imagePicker, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

我设置picker.navigationBar.isTranslucent = false在选择器控制器中有一个不透明的导航栏。不幸的是,这不适用于 iOS 13,并且导航和状态栏是透明的。

部分解决方案

private func setOpaqueNavigationiOS13() {
    UINavigationBar.appearance().backgroundColor = .white
}

private func resetNavigationiOS13() {
    UINavigationBar.appearance().backgroundColor = .clear
}
Run Code Online (Sandbox Code Playgroud)

我调用上述函数使导航栏不透明并在关闭选择器时将其重置。这使得导航栏不透明,但状态栏是透明的。我也可以实现一个 hack 使状态栏不透明,但我想应该有一个更简单的解决方案。

编辑:我还尝试通过新的 UINavigationBarAppearance 设置导航栏的外观:

if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller swift ios13

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

具有多个 id 的 iOS Firestore 复合查询

这是我在尝试将地理位置与 Firestore 混合使用时遇到的一个问题。长话短说 - 我需要用户所在位置附近的餐馆。为了完成地理搜索,我使用 Algolia。当我向 Algolia 发出请求时,它会返回一组唯一的餐厅 ID,这些 ID 对应于 Firestore 文档 ID。这很好用。

让事情变得复杂的是我还需要两个条件 - 我需要将查询限制为平均评分 >= 8 的餐厅。而且我还想限制返回文档的数量(2、5、20 等)。

所以它在伪代码中应该是这样的:

db.restaurantsCollection
    .documentIds([111, 222, 333, 444, 555, 666, 777, 888, 999])
    .whereField("averageRating", isGreaterThanOrEqualTo: 8)
    .order(by: "averageRating", descending: true)
    .limit(to: 2)
    .getDocuments()
Run Code Online (Sandbox Code Playgroud)

我知道截至今天 Firestore 不支持具有多个文档 ID 的查询。那么执行此类查询的最优化方法是什么?

如果我将 设为文档中的documentId一个id字段,然后迭代从 Algolia 返回的所有 id 并执行类似的操作(然后我可以在纯 Swift 中进行排序和限制):

for id in ids {
    db.restaurantsCollection
        .whereField("averageRating", isGreaterThanOrEqualTo: 8)
        .whereField("id", isEqualTo: id)
        .getDocuments()
}
Run Code Online (Sandbox Code Playgroud)

但这仍然意味着很多要求。还有其他想法吗?

swift algolia google-cloud-firestore

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