小编Jim*_*mmy的帖子

Swift 3:如何缩放和旋转UIImageView?

我真的很难在网上找到教程以及已经回答的问题(我已经尝试了它们,但它们似乎不起作用).我有一个UIImageView,我在我的视图中心.我现在可以在屏幕上的任何地方点击并拖动它.我希望能够缩放并旋转此视图.我该如何实现这一目标?我已尝试过下面的旋转代码,但它似乎不起作用?任何帮助都将是一个巨大的帮助,并标记为答案.感谢你们.

    import UIKit

class DraggableImage: UIImageView {

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        self.backgroundColor = .blue

    }

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

        self.backgroundColor = .green

    }

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        if let touch = touches.first {
            let position = touch.location(in: superview)
            center = CGPoint(x: position.x, y: position.y)
        }
    }

}

class CVController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white

        let rotateGesture = UIRotationGestureRecognizer(target: self, action: …
Run Code Online (Sandbox Code Playgroud)

uikit uipinchgesturerecognizer swift swift3

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

Swift 3:如何在自定义AVFoundation相机上启用闪光灯?

我有一个非常基本的AVFoundation相机,captureButton它会拍摄照片并将照片发送secondCameraController给它以供显示.我的问题是有很多iOS 10弃用,我不确定当我按下时,我是如何添加闪存的captureButton.任何帮助将受到高度赞赏.我的代码如下.感谢你们.

class CameraController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {

let captureSession = AVCaptureSession()
var previewLayer: CALayer!

var captureDevice: AVCaptureDevice!

var takePhoto: Bool = false

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    prepareCamera()
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    navigationController?.setNavigationBarHidden(true, animated: true)
}

let cameraView: UIView = {
    let view = UIView()
    view.backgroundColor = .red
    return view
}()

func prepareCamera() {
    captureSession.sessionPreset = AVCaptureSessionPresetPhoto

    if let …
Run Code Online (Sandbox Code Playgroud)

avfoundation swift swift3

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

Swift 3:如何点击单元格内的按钮并传递该单元格的indexPath?

我正在以编程方式进行所有操作,避免使用情节提要。我有一个collectionView,一个Post拥有用户名和密码的模型对象,当然我有collectionView单元格。我遇到的问题是,我的collectionView单元格内部有一个按钮。我希望能够点击此按钮并选择一个新的控制器。这是简单的部分。问题在于,我不仅要检入新控制器,还要传递我点击的按钮的特定Post Cell的特定用户名。我希望这是有道理的。基本上,我想拥有一个帖子,就像任何社交媒体应用程序一样,我想选择一个“个人资料”,并且还将该特定用户的用户名也传递给该个人资料控制器。希望您能理解。由于我在此问题上停留了一段时间,因此将给予任何帮助,我们将不胜感激。我当然会标记为答案。感谢大伙们...

class MyController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

var posts = [Post]()

override func viewDidLoad() {
    super.viewDidLoad()

    collectionView?.backgroundColor = .white
    collectionView?.register(CustomCell.self, forCellWithReuseIdentifier: "cellId")
}

override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return posts.count
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: view.frame.width, height: 50)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) …
Run Code Online (Sandbox Code Playgroud)

uitableview uicollectionview uicollectionviewcell swift swift3

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