小编eiv*_*dml的帖子

使用AutoLayout设置AVPlayer / AVPlayerLayer大小?

我正在尝试使用AutoLayout设置在视图中显示的视频的大小/帧。但是我不知道该怎么做。这是我认为的代码:

import UIKit
import AVKit

class VideoMeetingView: UIView {

    lazy var playerLayer: AVPlayerLayer = {
        let layer = AVPlayerLayer()
        return layer
    }()

    private lazy var videoView: UIView = {
        let view = UIView()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.backgroundColor = .blue
        return view
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = #colorLiteral(red: 0.5725490451, green: 0, blue: 0.2313725501, alpha: 1)
        self.addSubviewsAndConstraints()

        playerLayer.frame = videoView.bounds
        videoView.layer.addSublayer(playerLayer)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func addSubviewsAndConstraints() {
        self.addSubview(videoView) …
Run Code Online (Sandbox Code Playgroud)

ios avplayer avplayerlayer swift

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

是否可以同时在多个模拟器设备上进行iOS XCUITesting?

我有一个应用程序,它将在五个不同的设备上生产,使用相互交谈MultipeerConnectivity.我有一个bash脚本,可以在五个不同的模拟器上启动应用程序.这很好用,但是我每次都要点击每个设备来测试所有内容.

所以我想也许XCUITest可以帮助自动执行此操作,并删除这些外部bash脚本依赖项(希望在Xcode/Swift中执行所有操作).我试过这样一个天真的方法:

func testExample() {
    // Use recording to get started writing UI tests.
    // Use XCTAssert and related functions to verify your tests produce the correct results.

  let app1 = XCUIApplication(bundleIdentifier: "com.madebymist.qdb-ios")
  let app2 = XCUIApplication(bundleIdentifier: "com.madebymist.qdb-ios")
  app1.launch()
  app1.buttons["Select Group"].tap()
  app1.sheets.buttons["Group one"].tap()
  app1.buttons["Host"].tap()

  // Launch and test App 2
  app2.launch()
  app2.buttons["Select Group"].tap()
  app2.sheets.buttons["Group one"].tap()
  app2.buttons["Join"].tap()

}
Run Code Online (Sandbox Code Playgroud)

但是,这只是在同一个模拟器中逐个推出应用程序.

那么,有没有办法在多个模拟器设备上同时实现XCUITest?(最好在Xcode/Swift中,但其他选项也可以使用).

ios ios-simulator swift xcuitest

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

SwiftUI:如何在抚摸时使整个形状识别手势?

我正在使用一些形状在 SwiftUI 中创建一个自定义按钮。
作为一个最小的例子,我有一个实心矩形,由一个描边圆(无填充)包围。它被封装在一个 ZStack 中,并添加了一个 TapGesture。它有效,但我唯一的问题是正方形和圆形之间的空白区域不可点击。

如何在不向圆圈添加填充的情况下使圆圈内的所有内容均可点击?

struct ConfirmButton: View {
  var action: () -> Void

  var body: some View {
    ZStack {
      Circle()
        .stroke(Color.purple, lineWidth: 10.0)
        .padding(5)
      Rectangle()
        .fill(Color.red)
        .frame(width: 200, height: 200, alignment: .center)
    }.gesture(
      TapGesture()
        .onEnded {
          print("Hello world")
          self.action()
      }
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

swift swiftui

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

如何在 NSStatusBar 中绘制自定义视图?

我目前有一个带有显示标题的NSStatusBara 。NSStatusBarItem但我不想用自定义替换标题/文本NSView。我怎样才能做到这一点?

我目前有:

func applicationDidFinishLaunching(_ aNotification: Notification) {
    let statusBar = NSStatusBar.system
    statusBarItem = statusBar.statusItem(withLength: NSStatusItem.variableLength)
    statusBarItem.button?.title = "My Menu Bar App"
}
Run Code Online (Sandbox Code Playgroud)

假设我不想用以下内容替换标题:

let view = NSView(frame: NSRect(x: 0, y: 0, width: 40, height: 40))
view.layer?.backgroundColor = NSColor.yellow.cgColor
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我尝试将其作为子视图添加到按钮中,但没有成功。

macos cocoa nsstatusitem nsstatusbar swift

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

省略情感风格组件中的特定道具?

我有一个BoxWithAs组件,定义如下:

\n
const BoxWithAs = styled.div(\n  {\n    WebkitFontSmoothing: \'antialiased\',\n    MozOsxFontSmoothing: \'grayscale\'\n    // And more \xe2\x80\xa6\n  }\n);\n
Run Code Online (Sandbox Code Playgroud)\n

一切都很好,但现在我想弃用来自 的默认道具之一@emotion/styled,特别是asprop.

\n

我这样做了:

\n
type BoxWithAsType = typeof BoxWithAs;\ntype BoxProps = Omit<React.ComponentProps<BoxWithAsType>, \'as\'>;\n\n/**\n * Component that does it all.\n */\nconst Box = (props: BoxProps) => {\n  return <BoxWithAs {...props}>{props.children}</BoxWithAs>;\n};\n
Run Code Online (Sandbox Code Playgroud)\n

它确实删除了道具...

\n

在此输入图像描述

\n

...但现在组件本身丢失了所有StyledComponent类型信息。

\n

在此输入图像描述

\n

我如何构建这个才能实现两者?我的最终目标是弃用该as道具,而是鼓励使用.withComponent(出于 Typescript 的原因)。

\n

emotion typescript reactjs styled-components

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