30天学习Swift项目实战第四天------滑动菜单(UIScrollView)

30天学习Swift项目实战第四天------滑动菜单(UIScrollView),第1张

概述注意:项目分为3个界面,中间的界面使用了摄像头,模拟器是不能完成的。 源码分为4个文件: ViewController.swift: // // ViewController.swift // SlideMenu // // Created by luopan on 16/8/5. // Copyright © 2016年 Hust University. All rights reserved.

注意:项目分为3个界面,中间的界面使用了摄像头,模拟器是不能完成的。 源码分为4个文件: VIEwController.swift: // // VIEwController.swift // SlIDeMenu // // Created by luopan on 16/8/5. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit

class VIEwController: UIVIEwController {

@IBOutlet weak var scrollVIEw: UIScrollVIEw!overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()        UIApplication.sharedApplication().statusbarHIDden = true        let leftVIEw: leftVIEw = leftVIEw(nibname: "leftVIEw",bundle: nil)    let centerVIEw: Cameraview = Cameraview(nibname: "Cameraview",bundle: nil)    let rightVIEw: RightVIEw = RightVIEw(nibname: "RightVIEw",bundle: nil)            self.addChildVIEwController(leftVIEw)    self.scrollVIEw.addSubvIEw(leftVIEw.vIEw)    leftVIEw.dIDMovetoParentVIEwController(self)        self.addChildVIEwController(rightVIEw)    self.scrollVIEw.addSubvIEw(rightVIEw.vIEw)    rightVIEw.dIDMovetoParentVIEwController(self)        self.addChildVIEwController(centerVIEw)    self.scrollVIEw.addSubvIEw(centerVIEw.vIEw)    centerVIEw.dIDMovetoParentVIEwController(self)        var centerVIEwFrame: CGRect = centerVIEw.vIEw.frame    centerVIEwFrame.origin.x = self.vIEw.frame.wIDth    centerVIEw.vIEw.frame = centerVIEwFrame        var rightVIEwFrame: CGRect = rightVIEw.vIEw.frame    rightVIEwFrame.origin.x = 2 * self.vIEw.frame.wIDth    rightVIEw.vIEw.frame = rightVIEwFrame            self.scrollVIEw.contentSize = CGSizeMake(self.vIEw.frame.wIDth * 3,self.vIEw.frame.size.height)}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()    // dispose of any resources that can be recreated.}

}

leftVIEw: // // leftVIEw.swift // SlIDeMenu // // Created by luopan on 16/8/5. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit

class leftVIEw: UIVIEwController {

overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    //Status bar 给隐藏了    UIApplication.sharedApplication().statusbarHIDden = true        // Do any additional setup after loading the vIEw.}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()    // dispose of any resources that can be recreated.}/*// MARK: - Navigation// In a storyboard-based application,you will often want to do a little preparation before navigationoverrIDe func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) {    // Get the new vIEw controller using segue.destinationVIEwController.    // Pass the selected object to the new vIEw controller.}*/

}

RightVIEw: // // RightVIEw.swift // SlIDeMenu // // Created by luopan on 16/8/5. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit

class RightVIEw: UIVIEwController {

overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    //Status bar 给隐藏了    UIApplication.sharedApplication().statusbarHIDden = true    // Do any additional setup after loading the vIEw.}overrIDe func dIDReceiveMemoryWarning() {    super.dIDReceiveMemoryWarning()    // dispose of any resources that can be recreated.}/*// MARK: - Navigation// In a storyboard-based application,sender: AnyObject?) {    // Get the new vIEw controller using segue.destinationVIEwController.    // Pass the selected object to the new vIEw controller.}*/

}

Cameraview: // // Cameraview.swift // SlIDeMenu // // Created by luopan on 16/8/5. // copyright © 2016年 Hust University. All rights reserved. //

import UIKit //导入照相机框架 import AVFoundation

class Cameraview: UIVIEwController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{

@IBOutlet weak var cameraview: UIVIEw!@IBOutlet weak var tempImageVIEw: UIImageVIEw!//有关照相机的变量var captureSession : AVCaptureSession?var stillimageOutput : AVCaptureStillimageOutput?var prevIEwLayer : AVCaptureVIDeoPrevIEwLayer?overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    //去掉状态栏    UIApplication.sharedApplication().statusbarHIDden = true}overrIDe func vIEwDIDAppear(animated: Bool) {    super.vIEwDIDAppear(animated)        prevIEwLayer?.frame = cameraview.bounds}overrIDe func vIEwWillAppear(animated: Bool) {    super.vIEwWillAppear(animated)        captureSession = AVCaptureSession()    captureSession?.sessionPreset = AVCaptureSessionPreset1280x720        let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVIDeo)    var error : NSError?    var input: AVCaptureDeviceinput!        do {        input = try AVCaptureDeviceinput(device: backCamera) }    catch let error1 as NSError {        error = error1        input = nil    }        if (error == nil && captureSession?.canAddinput(input) != nil) {                captureSession?.addinput(input)                stillimageOutput = AVCaptureStillimageOutput()        stillimageOutput?.outputSettings = [AVVIDeoCodecKey : AVVIDeoCodecJPEG]                if (captureSession?.canAddOutput(stillimageOutput) != nil) {            captureSession?.addOutput(stillimageOutput)                        prevIEwLayer = AVCaptureVIDeoPrevIEwLayer(session: captureSession)            prevIEwLayer?.vIDeoGravity = AVLayerVIDeoGravityResizeAspect            prevIEwLayer?.connection.vIDeoOrIEntation = AVCaptureVIDeoOrIEntation.Portrait            cameraview.layer.addSublayer(prevIEwLayer!)            captureSession?.startRunning()        }            }    }func dIDPresstakePhoto(){        if let vIDeoConnection = stillimageOutput?.connectionWithMediaType(AVMediaTypeVIDeo){        vIDeoConnection.vIDeoOrIEntation = AVCaptureVIDeoOrIEntation.Portrait        stillimageOutput?.captureStillimageAsynchronouslyFromConnection(vIDeoConnection,completionHandler: {            (sampleBuffer,error) in                        if sampleBuffer != nil {                                                let imageData = AVCaptureStillimageOutput.jpegStillimageNSDataRepresentation(sampleBuffer)                let dataProvIDer  = CGDataProvIDerCreateWithCFData(imageData)                let cgImageRef = CGImageCreateWithJPEGDataProvIDer(dataProvIDer,nil,true,CGcolorRenderingIntent.RenderingIntentDefault)                                let image = UIImage(CGImage: cgImageRef!,scale: 1.0,orIEntation: UIImageOrIEntation.Right)                                self.tempImageVIEw.image = image                self.tempImageVIEw.hIDden = false                            }                                })    }        }var dIDTakePhoto = Bool()func dIDPresstakeAnother(){    if dIDTakePhoto == true{        tempImageVIEw.hIDden = true        dIDTakePhoto = false            }    else{        captureSession?.startRunning()        dIDTakePhoto = true        dIDPresstakePhoto()            }    }overrIDe func touchesBegan(touches: Set<UItouch>,withEvent event: UIEvent?) {    dIDPresstakeAnother()}

}

最后,我们有四个界面设计的文件。UIImageVIEw是没有用户交互功能是的,但是可以用一个UIVIEw来覆盖并设置用户交互属性就可以达到效果。

注意:所有的源码都可以找QQ是709165253的人要。 索要源码的时候,最好说明是在开源中国看到的。

总结

以上是内存溢出为你收集整理的30天学习Swift项目实战第四天------滑动菜单(UIScrollView)全部内容,希望文章能够帮你解决30天学习Swift项目实战第四天------滑动菜单(UIScrollView)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存