小编Giz*_*odo的帖子

iOS 8 UIVisualEffect UIBlurEffect和Scaling/Moving/Resizing

我有一个UIButton的子类,我模糊,看起来很棒:

- (id)initWithFrame:(CGRect)frame
    {
        if (self = [super initWithFrame:frame])
        {
            self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.0];
            UIVisualEffect *blurEffect;
            blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

            UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
            visualEffectView.frame = self.bounds;

            [self insertSubview:visualEffectView atIndex:0];
            visualEffectView.userInteractionEnabled = NO;

            self.layer.cornerRadius = 23.8;
            self.clipsToBounds = YES;

            self.titleLabel.font = [UIFont fontWithName:@"DINCondensed-Bold" size:15.0];
        }
        return self;
    }
Run Code Online (Sandbox Code Playgroud)

这些按钮必须经常移动(平移),调整大小和缩放,当我执行这些操作时,模糊消失并变为半透明视图.如果我使用框架/中心移动,使用CGAffineTransformation会发生这种情况.

有办法解决这个问题吗?

cgaffinetransform ios uiblureffect uivisualeffectview

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

像素格式:kCVPixelFormatType_32BGRA 与 AVVideoCodecJPEG

我正在尝试找出哪种方法可以更好地捕获 JPEG

AVFoundation -> PhotoCaptureDelegate

我可以用:

photoSettings = AVCapturePhotoSettings(format: [ kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA) ])
Run Code Online (Sandbox Code Playgroud)

或者

photoSettings = AVCapturePhotoSettings(format: [AVVideoCodecKey : AVVideoCodecJPEG, AVVideoCompressionPropertiesKey : [AVVideoQualityKey : 1.0]] as [String : Any])
Run Code Online (Sandbox Code Playgroud)

我注意到使用AVVideoCodecJPEG,我可以使用压缩质量;但是,如果我在PhotoCaptureDelegate中的CMSampleBuffer中执行任何 TIFF 转换或其他任务,则无法使用。

然而,如果我想以新的方式保存到 JPEG(猜测最有效的方式,我必须使用AVVideoCodecJPEG来执行以下操作:

func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {

    self.jpegPhotoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer, previewPhotoSampleBuffer: previewPhotoSampleBuffer)

    }
Run Code Online (Sandbox Code Playgroud)

使用哪个更好?

avfoundation ios cmsamplebuffer swift

5
推荐指数
0
解决办法
1405
查看次数

AVFoundation captureOutput didOutputSampleBuffer 延迟

我正在使用AVFoundation captureOutput didOutputSampleBuffer提取图像,然后用于过滤器。

\n\n
  self.bufferFrameQueue = DispatchQueue(label: "bufferFrame queue", qos: DispatchQoS.background,  attributes: [], autoreleaseFrequency: .inherit)\n\n  self.videoDataOutput = AVCaptureVideoDataOutput()\n  if self.session.canAddOutput(self.videoDataOutput) {\n       self.session.addOutput(videoDataOutput)\n       self.videoDataOutput!.alwaysDiscardsLateVideoFrames = true\n       self.videoDataOutput!.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]\n           self.videoDataOutput!.setSampleBufferDelegate(self, queue: self.bufferFrameQueue)\n  }\n\n\n\n func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {\n\n        connection.videoOrientation = .portrait\n\n        let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!\n        let ciImage = CIImage(cvPixelBuffer: pixelBuffer)\n\n        DispatchQueue.main.async {\n            self.cameraBufferImage = ciImage\n        }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

上面只是更新了self.cameraBufferImage上面只是在有新的输出样本缓冲区时

\n\n

然后,当按下滤镜按钮时,我使用self.cameraBufferImage如下:

\n\n
  func filterButtonPressed() {\n\n    if var …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios cmsamplebuffer swift avcaptureoutput

5
推荐指数
0
解决办法
1750
查看次数

iOS:Swift 中的 Opentype 字体功能

我得到了以下代码段来测试字体功能:

let font = UIFont(name: "MyFont", size: 18)
let features: NSArray = CTFontCopyFeatures(font!)!
print("properties = \(features)")
Run Code Online (Sandbox Code Playgroud)

使用扩展来使用功能:

    extension UIFont {

        func propotionalNumbers() -> UIFont {

            let originalFontDescriptor = self.fontDescriptor

            let fontDescriptorFeatureSettings = [
                [ UIFontFeatureTypeIdentifierKey: 1,
                  UIFontFeatureSelectorIdentifierKey: 0],
                [ UIFontFeatureTypeIdentifierKey: 16,
                  UIFontFeatureSelectorIdentifierKey: 4]
            ]

            let fontDescriptorAttributes = [UIFontDescriptorFeatureSettingsAttribute: fontDescriptorFeatureSettings]
            let fontDescriptor = originalFontDescriptor.addingAttributes(fontDescriptorAttributes)
            let font = UIFont(descriptor: fontDescriptor, size: 0)

            return font
        }
}
Run Code Online (Sandbox Code Playgroud)

问题

除了下面列出的一种特定字体外,上面的每种字体都运行良好:

OpenType TrueType

开放式特点:

  • 样式集
  • 分数
  • 表格
  • 升/降
  • 光盘。连字

但是,这是运行上述代码段时得到的结果:

properties = (
        { …
Run Code Online (Sandbox Code Playgroud)

xcode fonts opentype ios swift

5
推荐指数
0
解决办法
849
查看次数

AVFoundation - 提取高分辨率缓冲帧

AVfoundation提供以下方法来提取缓冲帧:

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!)
Run Code Online (Sandbox Code Playgroud)

但是,这仅提供低分辨率帧(最好是1920 x 1080).


func capturePhoto(with settings: AVCapturePhotoSettings, delegate: AVCapturePhotoCaptureDelegate)
Run Code Online (Sandbox Code Playgroud)

上面给出了完整的12mp(如果是最新的型号设备),但这是一次性交易.


对于长曝光复合,有没有办法在流中提取全分辨率帧?

buffer avfoundation ios long-integer swift

5
推荐指数
0
解决办法
235
查看次数

金属视图(MTKView)工程图尺寸问题

在这里,我有一个MTKView,并在相机Feed上实时运行了一个简单的CIFilter。这很好。

问题

在旧设备的自拍相机(如iPhone 5,iPad Air)上,提要会在较小的区域绘制。 更新:发现发生这种情况时,馈给MTKView的CMSampleBuffer的大小较小。我猜每次更新中的纹理都需要按比例放大吗?


 import UIKit
 import MetalPerformanceShaders
 import MetalKit
 import AVFoundation

    final class MetalObject: NSObject, MTKViewDelegate {

        private var metalBufferView            : MTKView?
        private var metalDevice                = MTLCreateSystemDefaultDevice()
        private var metalCommandQueue          : MTLCommandQueue!
        private var metalSourceTexture         : MTLTexture?
        private var context                    : CIContext?
        private var filter                     : CIFilter?


        init(with frame: CGRect, filterType: Int, scaledUp: Bool) {
            super.init()

            self.metalCommandQueue = self.metalDevice!.makeCommandQueue()
            self.metalBufferView = MTKView(frame: frame, device: self.metalDevice)
            self.metalBufferView!.framebufferOnly = false
            self.metalBufferView!.isPaused = true

            self.metalBufferView!.contentScaleFactor = UIScreen.main.nativeScale
            self.metalBufferView!.delegate = …
Run Code Online (Sandbox Code Playgroud)

xcode view ios metal

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

SpriteKit - Animate SKShapeNode形状路径

目前我正在使用Core Graphics作为形状,并将形状转换为CAShapeLayerCABasicAnimation路径动画不同的形状.

然而,由于游戏的复杂性,如果要介入SpritKit,使用SKShapeNode,(丢弃CAShapeLayer和使用SKShapeNode)我能够平滑地将其设置为不同的形状吗?

我没有看到一种SKAction可以让你改变路径的方法SKShapeNode.

提前致谢.

xcode ios sprite-kit skshapenode swift

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

Swift 5:字符串中的字符索引

在Swift 5之前,我已经使用了该扩展程序:

  fileprivate extension String {
        func indexOf(char: Character) -> Int? {
            return firstIndex(of: char)?.encodedOffset
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在,我收到了不赞成使用的消息:

'encodedOffset' is deprecated: encodedOffset has been deprecated as most common usage is incorrect. Use `utf16Offset(in:)` to achieve the same behavior.
Run Code Online (Sandbox Code Playgroud)

有没有一个更简单的解决方案,而不是使用 utf16Offset(in:)

我只需要作为Int传递回的字符位置的索引。

string indexof swift swift5

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

Swift 5 的 UnsafeMutablePointer 警告

我有这个:

let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: alpha) as UnsafeMutablePointer<vImagePixelCount>?
Run Code Online (Sandbox Code Playgroud)

现在我收到警告:

“UnsafeMutablePointer”(又名“UnsafeMutablePointer”)的初始化导致悬空指针

详细警告包括:

  1. 从'[vImagePixelCount]'(又名'Array')到'UnsafePointer'(又名'UnsafePointer')的隐式参数转换会产生一个指针,该指针仅在对'init(mutating:)'的调用期间有效

  2. 在 Array 上使用“withUnsafeBufferPointer”方法,以便将参数显式转换为对定义的范围有效的缓冲区指针

有没有解决的办法?

xcode pointers mutable ios swift

5
推荐指数
3
解决办法
4686
查看次数

iOS 16 中报告错误的界面方向

我一直在使用以下方法来检测 iOS 14/15 中当前的界面方向:

UIApplication.shared.windows.first!.windowScene!.interfaceOrientation 
Run Code Online (Sandbox Code Playgroud)

现在,在 iOS 16 Beta(1 和 2)中,它的报告不正确。风景被报道为肖像颠倒。

xcode rotation uiinterfaceorientation ios swift

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