小编Waz*_*zza的帖子

测试出现和消失的动画标签的文本

我正在努力测试一个标签(toastLabel)的外观,当有人输入错误的电子邮件时,我会对其进行短暂的动画制作.

private func registerNewUser(email: String, password: String, confirmationPassword: String) {
    if password == confirmationPassword {
        firebaseData.createUser(email: email, password: password, completion: { (error, _ ) in
            if let error = error {
                self.showToast(in: self.view, with: error.localizedDescription)
            } else {
                self.showToast(in: self.view, with: "Registered succesfully")
                self.signInUser(email: email, password: password)
            }
        })
    } else {
        //raise password mismatch error
        print("password mismatch error")
    }
}

func showToast(in toastSuperView: UIView, with text: String) {
    let toastLabel = ToastLabel()
    toastLabel.text = text
    toastSuperView.addSubview(toastLabel)
    layoutToastLabel(toastLabel)
    animateToastLabel(toastLabel)
} …
Run Code Online (Sandbox Code Playgroud)

xcode xctest swift

6
推荐指数
1
解决办法
476
查看次数

听听来自 iOS 的 Kotlin 协程流程

我已经设置了一个 Kotlin Multiplatform 项目并附加了一个SQLDelight数据库。它的所有设置和运行都正确,因为我已经使用以下方法在 android 端对其进行了测试:

通用主:

    val backgroundColorFlow: Flow<Color> =
            dbQuery.getColorWithId(BGColor.id)
                    .asFlow()
                    .mapToOneNotNull()
Run Code Online (Sandbox Code Playgroud)

MainActivity.kt使用以下方法在 Android 项目中触发良好:

database.backgroundColorFlow.onEach { setBackgroundColor(it.hex) }.launchIn(lifecycleScope)
Run Code Online (Sandbox Code Playgroud)

但是当尝试在 iOS 项目应用程序委托中访问相同的调用时,我得到以下选项,但我不确定如何使用它们或将它们转换为我的BGColor对象:

database.backgroundColorFlow.collect(collector: T##Kotlinx_coroutines_coreFlowCollector, completionHandler: (KotlinUnit?, Error?) -> Void)
Run Code Online (Sandbox Code Playgroud)

谁能帮助我如何使用它?

swift kotlin-multiplatform kotlin-coroutines

6
推荐指数
2
解决办法
2319
查看次数

无需使用 cocoapods 或其他外部 API 即可读取条形码图像

我正在尝试使用新的 Apple Vision API 从图像中检测条形码并返回其详细信息。我已成功检测到二维码并使用CIDetector. 但是我不能为一维条形码做这项工作。这是一个示例结果:

import UIKit
import Vision

class BarcodeDetector {

    func recognizeBarcode(for source: UIImage,
                            complete: @escaping (UIImage) -> Void) {
        var resultImage = source
        let detectBarcodeRequest = VNDetectBarcodesRequest { (request, error) in
            if error == nil {
                if let results = request.results as? [VNBarcodeObservation] {
                    print("Number of Barcodes found: \(results.count)")
                    if results.count == 0 { print("\r") }

                    var barcodeBoundingRects = [CGRect]()
                    for barcode in results {
                        barcodeBoundingRects.append(barcode.boundingBox)
                        let barcodeType = String(barcode.symbology.rawValue)?.replacingOccurrences(of: "VNBarcodeSymbology", with: "")
                        print("-Barcode …
Run Code Online (Sandbox Code Playgroud)

swift swift4 ios11 xcode9-beta apple-vision

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

容器未采用 BoxDecoration 图像的大小

我想将以下容器添加到 ListView,但该容器不采用作为装饰添加的图像的大小。如果我将图像添加为容器的子项,它工作正常,但我也想在图像顶部显示文本。

var imageListView = new List<Container>();
var container1 = new Container(
  margin: EdgeInsets.all(8.0),
  alignment: Alignment.bottomLeft,
  child: new Text('Order of The Day',
      style: new TextStyle(
          fontFamily: 'CallingAngelsPersonalUse',
          fontSize: 20.0,
          color: Colors.white
      ),
  ),
  decoration: new BoxDecoration(
    image: new DecorationImage(
      image: new AssetImage('assets/SVSunset.jpg'),
      fit: BoxFit.cover,
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

将容器添加到 ListView 然后显示如下:

imageListView.add(container1);

new ListView(children: imageListView)
Run Code Online (Sandbox Code Playgroud)

谁能看到我缺少什么吗?

dart flutter

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

具有Firebase存储和抖动的脱机图像持久性

如果我有互联网连接,我就可以成功拍摄照片并将其上传到Firebase。我还看到您可以将Firebase数据库设置为在脱机时持久保存数据,但是我看不到任何文档说明Firebase存储是否可行。

如果这不可能,那么解决这个问题的最佳方法是什么?我应该将图像另存为base64然后保存到sharedPreferences吗?还是作为实际文件然后上传?

感谢您的任何见解

dart firebase flutter

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

Flutter 相机插件无法导入/可用

开始在我的 flutter 应用程序上实现相机插件时出现以下错误:

  [VERBOSE-2:dart_error.cc(16)] Unhandled exception:
  MissingPluginException(No implementation found for method init on channel plugins.flutter.io/camera)
  #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:153:7)
  <asynchronous suspension>
  #1      _channel (package:camera/camera.dart:7:5)
  #2      _channel (package:camera/camera.dart:6:21)
  #3      availableCameras (package:camera/camera.dart:42:41)
  <asynchronous suspension>
  #4      main (file:///Users/waynerumble/Desktop/scott_and_viki/lib/main.dart:10:19)
  <asynchronous suspension>
  #5      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
  #6      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
  [VERBOSE-2:dart_error.cc(16)] Unhandled exception:
  MissingPluginException(No implementation found for method list on channel plugins.flutter.io/camera)
  #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:153:7)
  <asynchronous suspension>
  #1      availableCameras (package:camera/camera.dart:42:50)
  <asynchronous suspension>
  #2      main (file:///Users/waynerumble/Desktop/scott_and_viki/lib/main.dart:10:19)
  <asynchronous suspension>
  #3      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
  #4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
Run Code Online (Sandbox Code Playgroud)

直到我开始使用该插件本身,也就是说,如果我更换,不会发生错误 …

dart flutter

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

客户没有与ID相关联的来源

查看条带测试trasactions时,我一直收到以下错误:

{
  "error": {
    "type": "invalid_request_error",
    "message": "Customer cus_9tW8Cf0Xvm9lRv does not have a linked source with ID tok_19Zj5rAANnhOmz4ex3ri2jtW.",
    "param": "source",
    "code": "missing"
  }
}
Run Code Online (Sandbox Code Playgroud)

我调用api的快速代码如下:

    @IBAction func payButtonWasPressed() {
        stripeCard = STPCardParams()

        let expirationDate = self.cardExpiryTextField.text!.components(separatedBy: "/")
        let expMonth = UInt(expirationDate[0])
        let expYear = UInt(expirationDate[1])

        stripeCard.number = self.cardNumberTextField.text
        stripeCard.cvc = self.cardCVVTextField.text
        stripeCard.expMonth = expMonth!
        stripeCard.expYear = expYear!

        STPAPIClient.shared().createToken(withCard: stripeCard, completion: { (token, error) -> Void in

            if error != nil {
                self.handleError(error! as NSError)
                return
            } 

            self.chargeUsingToken(token!)
        })
    }

    func …
Run Code Online (Sandbox Code Playgroud)

stripe-payments swift

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

使用isSecureTextEntry = true测试文本字段时,访问ID不起作用

因此,我尝试访问并确认我的uitest中是否存在密码文本字段,但是一旦分配了它们isSecureTextEntry = true,测试就无法再通过accessID找到它们。有谁知道为什么吗?并且是否有办法解决这个问题,以便我可以找到它们并在测试中使用它们?最好让我仍然可以使用访问ID在测试中找到它们。

我的测试很简单:

func testHasPasswordTextField() {
    let passwordTextField = app.textFields[AccesID.passwordTextField]

    XCTAssertTrue(passwordTextField.isHittable)
}
Run Code Online (Sandbox Code Playgroud)

运行测试时出现以下错误:

“未找到与Find匹配的元素:来自输入{(TextField,0x600000193e80,traits:146029150208,identifier:'Email',placeholderValue:'Email')}的与谓词'“ Password” IN identifiers匹配的元素

如果isSecureTextEntry = false(或未设置)测试顺利通过,

io xcode xctest swift xcuitest

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

使用异步变量初始化类

如何使用异步变量初始化类,以便在使用该类之前设置它们?我的类当前只是调用一个async init函数,但我必须单独调用该函数才能等待它完成:

class Storage {

  String imageDirectory;
  String jsonDirectory;
  SharedPreferences instance;
  String uuid;

  init() async {
    imageDirectory = '${(await getApplicationDocumentsDirectory()).path}/image_cache/';
    jsonDirectory = '${(await getApplicationDocumentsDirectory()).path}/json_cache/';
    instance = await SharedPreferences.getInstance();
    uuid = instance.getString("UUID");
  }
}
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

dart

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

使用 client.fetchArray 时出现内容错误

当我尝试按照本教程进行操作时,出现以下错误:

哦,没有出什么问题:A response for the QueryOn<Thing> did return successfully, but a serious error occurred when decoding the array of Thing. Double check that you are passing Thing.self, and references to all other EntryDecodable classes into the Client initializer.

当使用以下代码调用contentful时:

func fetch() {
    let query = QueryOn<Thing>.where(field: .description, .exists(true))

    client.fetchArray(of: Thing.self, matching: query) { (result: Result<ArrayResponse<Thing>>) in

        switch result {
        case .success(let things):
            guard let firstThing = things.items.first else { return }
            print(firstThing)
        case .error(let error):
            print("Oh no something …
Run Code Online (Sandbox Code Playgroud)

swift contentful

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

全名正则表达式不起作用

我试图使用正则表达式来验证颤振中文本字段表单的全名,但我无法弄清楚它为什么不起作用。

我从这里 找到的表达式/^[a-z ,.'-]+$/i对于我给出的任何条目都失败了。

我在 dart 中为我的颤振应用程序使用的代码是:

final RegExp nameExp = new RegExp(r"/^[a-z ,.'-]+$", caseSensitive: false);
Run Code Online (Sandbox Code Playgroud)

谁能看到我错过了什么?

更新:所以正则表达式允许大多数事情并且不太正确,对我有用的是r"^([a-zA-Z]{2,}\s[a-zA-z]{1,}'?-?[a-zA-Z]{2,}\s?([a-zA-Z]{1,})?)"下面接受的答案

regex dart flutter

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

谓词匹配一对多关系核心数据

我正在尝试获取在 coredata 中有许多与其相关的项目的账单的总价。我正在努力理解检索项目所需的谓词语法,以便我可以访问它们的价格。我不断收到以下错误:

    2016-12-14 14:13:12.309 Splitter[43533:5597917] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (ANY items IN <Splitter.Bill: 0x7fe6e0cebbd0> (entity: Bill; id: 0xd000000000300000 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Bill/p12> ; data: {
    date = "December 14, 2016";
    id = "6D672183-44C2-4961-ABB6-27FD657E5C68";
    items =     (
    "0xd000000001fc0012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p127>",
    "0xd0000000020c0012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p131>",
    "0xd000000002080012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p130>",
    "0xd000000002100012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p132>",
    "0xd000000002040012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p129>",
    "0xd000000001f00012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p124>",
    "0xd000000001f80012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p126>",
    "0xd000000001e80012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p122>",
    "0xd000000001f40012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p125>",
    "0xd000000001ec0012 <x-coredata://D13BAFFD-A78A-4C49-9992-F975887B7AB7/Item/p123>",
    "(...and 1 more...)"
    );
    location = hgfhgfd;
    name = hgfhgfd;
    total = 0;
    }))'
Run Code Online (Sandbox Code Playgroud)

从以下代码: …

core-data ios swift

0
推荐指数
1
解决办法
1586
查看次数

动画视图以隐藏/缩放到其右下角

当按下取消按钮时,我试图让视图缩小到右下角的任何内容。目前当我使用时:

    UIView.animate(withDuration: 0.7, delay: 0, options: .beginFromCurrentState, animations: {
        self.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
    })
Run Code Online (Sandbox Code Playgroud)

视图缩小到中心。

我知道我应该设置图层的锚点,以便它收缩到该点,但是当我这样做时,它将视图中心移动到该点然后收缩:

    UIView.animate(withDuration: 0.7, delay: 0, options: .beginFromCurrentState, animations: {
        self.layer.anchorPoint = CGPoint(x: 0.0, y: 0.0)
        self.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
    })
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

编辑:更多信息是我使用制图术将视图的约束设置为边缘viewController.view,我想知道这是否与它有关?

swift

0
推荐指数
1
解决办法
1482
查看次数