小编uti*_*nia的帖子

什么是NSISEngine?

我正在浏览我的应用程序并且我注意到当我加载某些(确切地说是112个中的4个)对象并将其加载到ViewController4 UIStackView秒内所有用代码编写(即没有xib)时,会出现明显的滞后加载,特别是加载UIStackViews时.我运行了一个性能跟踪,并注意到快速加载的视图与滞后的视图之间的唯一区别是NSISEngine被调用的方法需要大约6倍(特别是[NSISEngine Optimize]).有谁知道为什么这只会出现<5%的案例?

  • 每个对象的数据量无关紧要,因为有大型对象没有此问题.
  • 我使用的是自定义UIStackView的,可以在点击时展开,这是我正在使用的代码:

     func toggle() {
        // only toggle if there's a subView
        guard subView != nil else {
            return
        }
        let rotation = isExpanded ? 0 : ? / 2
        isExpanded = !isExpanded
        setSpacing(for: self) // this takes 1e-6s 
        t1 = Date()
        UIView.animate(withDuration: kExpansionTime, animations: {
            self.arrowView.transform = CGAffineTransform(rotationAngle: rotation)
            self.subView?.isHidden = !self.isExpanded
            self.layoutIfNeeded() // no change if this is removed.
        }) {_ in
            t2 = …
    Run Code Online (Sandbox Code Playgroud)

ios swift

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

从UIScrollView Objective C创建PDF

这个问题之前已经发布过(从iphone应用程序中的UIScrollView创建PDF),我正在使用的代码来自这里.

这是代码

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories …
Run Code Online (Sandbox Code Playgroud)

objective-c uiscrollview ios

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

关闭UIAlertController后执行segue

在过去,我曾经遇到过类似的问题,即UIAlertControllerUIAlertController取消后,UI线程上总是存在滞后。
我现在的问题是,如果用户单击“确定”,我想执行顺序检查,如果按下UIAlertAction“取消”,UIAlertAction则什么也不会发生。
这是我的代码:

// create the uialertcontroller to display
let alert = UIAlertController(title: "Do you need help?",
                              message: "Would you like to look for a consultant?",
                              preferredStyle: .alert)
// add buttons
let okay = UIAlertAction(title: "Yes, please.", style: .default, handler: {_ in
    self.performSegue(withIdentifier: "segue", sender: nil)
})
let no = UIAlertAction(title: "No, I'm okay.", style: .cancel, handler: nil)
alert.addAction(okay)
alert.addAction(no)
self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当前正在发生的是,当我点击“确定”时,segue正在执行,但是我只能看到过渡的最后时刻(即,动画在UIAlertController被关闭时开始播放)。
一旦UIAlertController解散,我如何使segue开始?

注意-如果有其他方法,我宁愿不要以骇人的方式解决此问题,例如在固定的延迟后执行segue。 …

segue swift uialertcontroller

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

在 MTKView 上渲染 MTLTexture 不保持宽高比

我有一个 1080x1920 像素的纹理。MTKView我正在尝试以不同的纵横比渲染它。(即iPad/iPhone X全屏)。

这就是我渲染纹理的方式MTKView

private func render(_ texture: MTLTexture, withCommandBuffer commandBuffer: MTLCommandBuffer, device: MTLDevice) {
    guard let currentRenderPassDescriptor = metalView?.currentRenderPassDescriptor,
            let currentDrawable = metalView?.currentDrawable,
            let renderPipelineState = renderPipelineState,
            let encoder = commandBuffer.makeRenderCommandEncoder(descriptor: currentRenderPassDescriptor) else {
                semaphore.signal()
                return
        }

    encoder.pushDebugGroup("RenderFrame")
    encoder.setRenderPipelineState(renderPipelineState)
    encoder.setFragmentTexture(texture, index: 0)
    encoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 4, instanceCount: 1)
    encoder.popDebugGroup()
    encoder.endEncoding()

    // Called after the command buffer is scheduled
    commandBuffer.addScheduledHandler { [weak self] _ in
        guard let strongSelf = self else {
            return …
Run Code Online (Sandbox Code Playgroud)

ios swift metal metalkit

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