在SwiftUI中,是否有人知道控制事件(例如:scrollViewDidScroll)在哪里,以检测用户何时到达列表的底部,从而导致事件检索其他数据块?还是有一种新的方法来做到这一点?
好像UIRefreshControl()也不存在...
我已经安装了iOS 13 beta版并运行了包含很多网络请求的框架,但是出现了以下错误:
2019-09-19 15:01:33.566811+0200 ---[395:25439] Connection 4: default TLS Trust evaluation failed(-9814)
2019-09-19 15:01:33.567022+0200 ---[395:25439] Connection 4: TLS Trust encountered error 3:-9814
2019-09-19 15:01:33.567110+0200 ---[395:25439] Connection 4: encountered error(3:-9814)
2019-09-19 15:01:33.569824+0200 ---[395:25439] Connection 4: unable to determine interface type without an established connection
2019-09-19 15:01:33.584952+0200 ---[395:25439] Task <D97FD611-0B48-4DCE-99C9-6A971E5E6524>.<4> HTTP load failed, 0/0 bytes (error code: -1202 [3:-9814])
Run Code Online (Sandbox Code Playgroud)
我试图找出导致该问题的原因,但没有成功。谁能帮我?
我想模糊视图的背景,但是不想闯入UIKit来完成它(例如a UIVisualEffectView
)。我正在研究文档,却一无所获,似乎没有办法实时剪切背景并对其应用效果。我是错误的还是以错误的方式调查它?
有没有办法在tvOS应用中检测苹果电视是否已越狱?尝试使用与iPhone中使用的方法相同的方法来检测越狱,但按参考链接无法正常工作- 如何检测越狱手机上是否正在运行iOS应用?
NSString *filePath = @"/Applications/Cydia.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
// do something useful
}
Run Code Online (Sandbox Code Playgroud)
此方法不起作用,任何特定于tvOS应用程序的API可以检测越狱?
使用Apple的新的Combine框架,我希望从列表中的每个元素发出多个请求。然后,我希望减少所有响应得到一个结果。基本上,我想从发布者列表转到拥有响应列表的单个发布者。
我尝试列出发布者列表,但是我不知道如何将列表缩小为一个发布者。而且我尝试过使发布者包含一个列表,但是我无法平面映射发布者列表。
请查看“ createIngredients”功能
func createIngredient(ingredient: Ingredient) -> AnyPublisher<CreateIngredientMutation.Data, Error> {
return apollo.performPub(mutation: CreateIngredientMutation(name: ingredient.name, optionalProduct: ingredient.productId, quantity: ingredient.quantity, unit: ingredient.unit))
.eraseToAnyPublisher()
}
func createIngredients(ingredients: [Ingredient]) -> AnyPublisher<[CreateIngredientMutation.Data], Error> {
// first attempt
let results = ingredients
.map(createIngredient)
// results = [AnyPublisher<CreateIngredientMutation.Data, Error>]
// second attempt
return Publishers.Just(ingredients)
.eraseToAnyPublisher()
.flatMap { (list: [Ingredient]) -> Publisher<[CreateIngredientMutation.Data], Error> in
return list.map(createIngredient) // [AnyPublisher<CreateIngredientMutation.Data, Error>]
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定如何获取发布者数组并将其转换为包含数组的发布者。
类型“ [AnyPublisher]”的结果值与关闭结果类型“ Publisher”不符
在UIViewController
Swift 的正常情况下,我使用此代码发送邮件。
let mailComposeViewController = configuredMailComposeViewController()
mailComposeViewController.navigationItem.leftBarButtonItem?.style = .plain
mailComposeViewController.navigationItem.rightBarButtonItem?.style = .plain
mailComposeViewController.navigationBar.tintColor = UIColor.white
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
Run Code Online (Sandbox Code Playgroud)
如何在SwiftUI中实现相同目标?
我需要使用UIViewControllerRepresentable
吗?
在UIKit中,绘制描边和填充的路径/形状非常简单。
例如,下面的代码绘制了一个蓝色的红色圆圈。
override func draw(_ rect: CGRect) {
guard let ctx = UIGraphicsGetCurrentContext() else { return }
let center = CGPoint(x: rect.midX, y: rect.midY)
ctx.setFillColor(UIColor.red.cgColor)
ctx.setStrokeColor(UIColor.blue.cgColor)
let arc = UIBezierPath(arcCenter: center, radius: rect.width/2, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true)
arc.stroke()
arc.fill()
}
Run Code Online (Sandbox Code Playgroud)
SwiftUI如何做到这一点?
Swift UI似乎支持:
Circle().stroke(Color.blue)
// and/or
Circle().fill(Color.red)
Run Code Online (Sandbox Code Playgroud)
但不是
Circle().fill(Color.red).stroke(Color.blue) // Value of type 'ShapeView<StrokedShape<Circle>, Color>' has no member 'fill'
// or
Circle().stroke(Color.blue).fill(Color.red) // Value of type 'ShapeView<Circle, Color>' has no member 'stroke'
Run Code Online (Sandbox Code Playgroud)
我应该只是ZStack两个圈子吗?这似乎有点愚蠢。
如果我有一个SwiftUI Color
:
let col: Color = Color(red: 0.5, green: 0.5, blue: 0.5)
Run Code Online (Sandbox Code Playgroud)
如何从中获取RGB分量col
?
像这样:
print(col.components.red)
Run Code Online (Sandbox Code Playgroud)
在UIKit中,我可以使用,UIColor.getRed
但SwiftUI中似乎没有等效项。
需要使用 SwiftUI 创建图像网格,根据屏幕宽度动态更改行。
当我使用时List
,我只能得到一列..
我尝试使用 Hstacks 制作 2 列,但它不能动态适应屏幕宽度。
例如:iPhone 纵向应有 1 列 示例:iPhone 横向应有 2 列
import SwiftUI
struct ProductGrid : View {
var body: some View {
List(0 ..< 5) { item in
VStack() {
Image("product")
HStack {
ProfileImageSmall()
VStack {
Text("Product")
Text("Username")
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何制作一个列数适应屏幕宽度的网格?
我很难理解为什么会这样。我将问题简化为最小表达。
我有一个Text
观点,即移除后应该淡出。在.transition(.opacity)
已经加入只是为了清楚。不需要它,因为它是默认值。但是,结果是,除了淡入淡出之外,文本视图还向右滑动。
通过播放文本长度,我意识到在过渡期间,其左边界要与CHANGE按钮的左边界对齐。但为什么?!
相反,添加回去时,它工作正常并且没有运动。只是一个很好的淡入效果。
该问题不仅发生在iOS,而且发生在macOS。使用Xcode 11 beta 2。
import SwiftUI
struct ContentView : View {
@State private var showText = true
var body: some View {
VStack {
Spacer()
if showText {
Text("I should always be centered!").font(.largeTitle).transition(.opacity)
}
Spacer()
Button(action: {
withAnimation(.basic(duration: 1.5)) { self.showText.toggle() }
}, label: {
Text("CHANGE").font(.title)
})
Spacer()
}
}
}
Run Code Online (Sandbox Code Playgroud)