我正在尝试使用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) 我有一个应用程序,它将在五个不同的设备上生产,使用相互交谈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中,但其他选项也可以使用).
我正在使用一些形状在 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)
我目前有一个带有显示标题的NSStatusBar
a 。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)
我怎样才能做到这一点?我尝试将其作为子视图添加到按钮中,但没有成功。
我有一个BoxWithAs
组件,定义如下:
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
,特别是as
prop.
我这样做了:
\ntype 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
类型信息。
我如何构建这个才能实现两者?我的最终目标是弃用该as
道具,而是鼓励使用.withComponent
(出于 Typescript 的原因)。
swift ×4
ios ×2
avplayer ×1
cocoa ×1
emotion ×1
macos ×1
nsstatusbar ×1
nsstatusitem ×1
reactjs ×1
swiftui ×1
typescript ×1
xcuitest ×1