本文已参加「新人创作礼」活动,一同敞开创作之路。
【ios开发/Xcode】完结多功用备忘录
引言
一、项目来源及含义 跟着当今年代科技不断的进步开展,现代快节奏的日子方式让人们每天都有许多行程组织,都是往往由于业务的堆积导致人们常常把要做的业务遗忘,或者想要及时记载的信息得不到记载。 在今日这个充满着各种剧烈竞赛的重压年代,每个人都在繁忙的日子着。当今年代下对下一代人要培育许多专长的一起还要让他们完结学校布置的作业,而咱们作为大学生学习任务相同很重,还面临这就业等问题,在咱们这般的繁忙琐碎日常日子中,会有许多需求回忆的工作。但人的回忆是有限的,咱们需求一个能提醒和组织咱们工作的东西,怎么有条不紊的处理和组织任务,在有限的时间内完结最紧迫最重要的事情,备忘录对咱们而言尤为重要。 一起,在平常工作劳累之余的碎片化时间中,怎么简单的放松自我也是及其重要的问题。因而我推出了一个简单易操作的多功用备忘录,在记载保存重要的信息的一起还顺便核算与放松功用,极其好用。
二、项目开发平台及技术简要说明 体系:MAC OS 10.14 环境:XCode 10.2 Swift 4.3
三、项目需求剖析及规划 该项目首要完结了一个多功用备忘录,包括漫笔便签、核算器以及音乐播映器。在漫笔便签中,每个人所保存的便签信息不同,所以依据账号可以完结显现不同的便签信息。而在需求添加便签时,可以写入新便签,并以标题的方式显现。在管理便签信息的时分可以进行删去或者调整次序等操作,当然数据要可以持久化保存。而核算器与音乐播映器则可以直接进行运用。 用户可以在注册页面注册新的账号,在运用账号登录成功后转入登录成功界面,管理和检查页面中可以检查当前存在的便签,以标题和时间的方式显现。接着可以进行信息修正包括添加删去和修正次序等等。让你做到一件事都不漏,彻底帮你管理起你的日子和工作。 在未登录时,用户可以运用核算器进行对一些事物以及数据的核算,较为便利。一起还可以听听音乐,放松放松。音乐还提供的多倍数与低倍数功用,可以尽情的依据自己的兴趣调节,十分人性化。 综上所述,依据这些功用该项目一共规划了7个首要页面:欢迎界面、登录页面、注册页面、管理和检查页面、修正页面、音乐播映界面以及核算器界面。
四、项目完结 项目代码结构
项目故事版
具体功用及完结
注:@开头的这些代码都是需求相关控键,都需求自行在故事板中(Storyboards)进行相关 1、登录 输入体系中现已存储的或注册的账号密码可以进行登录
登录界面首要源代码
class LoginViewController : UIViewController{
//键盘辨认
@IBAction func dismissKeyborad(_ sender: UITapGestureRecognizer) {
userId.resignFirstResponder()
password.resignFirstResponder()
}
//用户名
@IBOutlet weak var userId: UITextField!
//密码
@IBOutlet weak var password: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
var userpwd = [String:String]()
//登录
@IBAction func Login(_ sender: UIButton) {
let user = userId.text!
let pwd = password.text!
userpwd = UserDefaults.standard.object(forKey: "userpwd")as?[String:String] ?? [String:String]()
if userpwd[user] == pwd {
self.performSegue(withIdentifier: "LoginSuccess", sender: nil)
} else {
let alertController = UIAlertController(title: "登录失败!",message: nil, preferredStyle: .alert)
self.present(alertController, animated: true,completion: nil)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {self.presentedViewController?.dismiss(animated: false, completion: nil)}
}
}
}
2、注册 若无账号密码则需求注册,点击输入用户名与密码后点击注册即可完结注册,注册成功后弹窗显现“注册成功!”
注册界面首要源代码
class RegisterViewController : UIViewController{
@IBOutlet weak var userId: UITextField!
@IBOutlet weak var password: UITextField!
@IBAction func dismissKeyBoard1(_ sender: UITapGestureRecognizer) {
userId.resignFirstResponder()
password.resignFirstResponder()
}
var userpwd = [String:String]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//回来
@IBAction func backLo(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
//注册
@IBAction func register(_ sender: Any) {
let user = userId.text!
let pwd = password.text!
userpwd = UserDefaults.standard.object(forKey: "userpwd")as?[String:String] ?? [String:String]()
userpwd[user] = pwd
UserDefaults.standard.set(userpwd, forKey: "userpwd")
UserDefaults.standard.synchronize()
let ok = UIAlertAction(title:"确认", style:.default){
action in self.dismiss(animated: true,completion: nil)
}
let alter = UIAlertController(title: "注册成功!",message: nil, preferredStyle: .alert)
alter.addAction(ok)
self.present(alter,animated:true,completion:nil)
}
}
3、备忘录
此功用为备忘录的主页面,页面中有“回来”、“添加”与“修正”按钮,点击对应按钮完结对应功用。
注册界面首要源代码
class EducationalSystemViewController : UITableViewController{
var studentList: StudentList
//添加
@IBAction func addStudent(_ sender: UIButton) {
let theStudent = studentList.addStudent()
if let theIndex = studentList.students.index(of:theStudent){
let theIndexPath = IndexPath(row: theIndex, section: 0)
tableView.insertRows(at: [theIndexPath], with: .automatic)
}
studentList.saveStudents()
}
//回来
@IBAction func back(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
//修正
@IBAction func shiftEditMode(_ sender: UIButton) {
if isEditing{
sender.setTitle("修正", for: .normal)
setEditing(false, animated: true)
}else{
sender.setTitle("确认", for: .normal)
setEditing(true, animated: true)
}
}
override func viewDidLoad() {
studentList = StudentList()
let statusBarHeight = UIApplication.shared.statusBarFrame.height
let insets = UIEdgeInsets(top: statusBarHeight, left: 0, bottom: 0, right: 0)
tableView.contentInset = insets
tableView.scrollIndicatorInsets = insets
let theRefreshControl = UIRefreshControl()
theRefreshControl.attributedTitle = NSAttributedString(string: "refreshing")
theRefreshControl.addTarget(self, action: #selector(refreshing), for: UIControl.Event.valueChanged)
refreshControl = theRefreshControl
}
@objc func refreshing(){
if(refreshControl?.isRefreshing == true){
refreshControl?.attributedTitle = NSAttributedString(string: "loading...")
refreshControl?.endRefreshing()
refreshControl?.attributedTitle = NSAttributedString(string: "refreshing")
tableView.reloadData()
}
}
required init?(coder aDecoder: NSCoder) {
studentList = StudentList()
super.init(coder: aDecoder)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return studentList.students.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath) as! StudentCell
let student = studentList.students[indexPath.row]
cell.nameLabel.text = student.name
cell.scoreLabel.text = "\(student.score)"
cell.idLabel.text = student.id
return cell
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{
let theStudent = studentList.students[indexPath.row]
studentList.deleteStudent(theStudent)
tableView.deleteRows(at: [indexPath], with: .automatic)
}
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
studentList.transferPosition(sourceIndex: sourceIndexPath.row, destinationIndex: destinationIndexPath.row)
}
}
4、备忘录增修正查、数据持久化等操作 点击“添加”,则会在备忘录的最终添加一条备忘录信息,点击“修正”进入修正界面,可以移动和删去备忘录中的信息。
增修正查首要源代码
class StudentList{
var students=[Student]()
let archiveURL: URL = {
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let document = documents.first!
return document.appendingPathComponent("studentistList1.plist")
}()
init(){
let fileExist = FileManager.default.fileExists(atPath: archiveURL.path)
if !fileExist {
let bundlePath = Bundle(for: StudentList.self).resourcePath as NSString?
let thePath = bundlePath!.appendingPathComponent("studentsCollection.plist")
do{
try FileManager.default.copyItem(atPath: thePath, toPath: archiveURL.path)
}catch{
print("fail to copy plist file!")
}
}
let theCollection = NSMutableArray(contentsOfFile: archiveURL.path)!
for theElement in theCollection{
let dict = theElement as! NSDictionary
let name = dict["name"] as! String
let score = dict["score"] as! String
let id = dict["id"] as! String
let theStudent = Student(name: name, score: score, id: id)
students.append(theStudent)
}
}
//添加
func addStudent() -> Student {
let theStudent = Student(name: "今日", score: "预备辩论!", id: "8:00")
students.append(theStudent)
saveStudents()
return theStudent
}
//删去
func deleteStudent(_ theStudent:Student) {
if let theIndex = students.index(of: theStudent){
students.remove(at: theIndex)
saveStudents()
}
}
//修正
func transferPosition(sourceIndex: Int, destinationIndex: Int) {
if sourceIndex != destinationIndex {
let theStudent = students[sourceIndex]
students.remove(at: sourceIndex)
students.insert(theStudent, at: destinationIndex)
}
return
}
//保存
func saveStudents() -> Bool{
let studentsArray = NSMutableArray()
for theStudent in students{
let studentDictionary : NSDictionary
studentDictionary = ["name":theStudent.name,"id":theStudent.id,"score":"\(theStudent.score)"]
studentsArray.add(studentDictionary)
}
studentsArray.write(toFile: archiveURL.path,atomically: true)
print(archiveURL)
return true
}
}
下图所示为备忘录初始储存的备忘信息
5、音乐播映器 在“放松一下”功用中可以播映一段美丽的音乐,一起可以依据自己的心情调节音乐的快慢,点击对应的按钮即可完结。
音乐播映器界面源代码
class bgmController: UIViewController {
//图片展现
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
//获取图片途径
guard let path = Bundle.main.path(forResource: "p1.gif", ofType: nil),
let data = NSData(contentsOfFile: path),
let imageSource = CGImageSourceCreateWithData(data, nil) else { return }
var images = [UIImage]()
var totalDuration : TimeInterval = 0
for i in 0..<CGImageSourceGetCount(imageSource) {
guard let cgImage = CGImageSourceCreateImageAtIndex(imageSource, i, nil) else { continue }
let image = UIImage(cgImage: cgImage)
i == 0 ? imageView.image = image : ()
images.append(image)
guard let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, i, nil) as? NSDictionary,
let gifDict = properties[kCGImagePropertyGIFDictionary] as? NSDictionary,
let frameDuration = gifDict[kCGImagePropertyGIFDelayTime] as? NSNumber else { continue }
totalDuration += frameDuration.doubleValue
}
imageView.animationImages = images
imageView.animationDuration = totalDuration
imageView.animationRepeatCount = 0
imageView.startAnimating()
}
lazy var player: AVAudioPlayer? = {
let url = Bundle.main.url(forResource: "bgm.mp3", withExtension: nil)
do {
let player = try AVAudioPlayer(contentsOf: url!)
player.delegate = self
// 播映速率
player.enableRate = true
// 预备播映
player.prepareToPlay()
return player
}catch {
print(error)
return nil
}
}()
// 获取音乐
func playBack() -> () {
let audioSession: AVAudioSession = AVAudioSession.sharedInstance()
do {
if #available(iOS 10.0, *) {
try audioSession.setCategory(.playback, mode: .default, options: .defaultToSpeaker)
} else {
}
try audioSession.setActive(true)
}catch {
print(error)
}
}
//开始
@IBAction func play() {
playBack()
player?.play()
}
//暂停
@IBAction func pauseM(_ sender: Any) {
player?.pause()
}
//中止
@IBAction func stopM(_ sender: UIButton) {
player?.currentTime = 0
player?.stop()
}
//快速
@IBAction func kuaisu(_ sender: UIButton) {
player?.rate = 3
}
//原速
@IBAction func yuansu(_ sender: UIButton) {
player?.rate = 1
}
//慢速
@IBAction func mansu(_ sender: UIButton) {
player?.rate = 0.5
}
//回来
@IBAction func back(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
}
extension bgmController: AVAudioPlayerDelegate {
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
}
}
6、核算器 核算器功用中完结了规范核算器的核算功用,包括加减乘除、三角函数、幂等等。
核算器界面源代码
class calculatorCTL: UIViewController {
var Priority = ["+","-","*","","="]
var isEq:Bool = false//判别是否输入等于号
var isMinus:Bool = false//判别是否负数
var isControl:Bool = false//判别是否输入操作符
var input:Double = 0.0//存储输入数字
var lastRes:Double = 0.0//存储上一个数字
var res:Double = 0.0//存储答案
var fh:Int = 0//符号符号
var math:Int = 0//运算符符号
//回来
@IBAction func back(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
//结果显现
@IBOutlet weak var resultsum: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
//数字
@IBAction func takesum(_ sender: UIButton) {
if isMinus {
resultsum.text = "0"
}
if isControl{
resultsum.text = "0"
}
if(resultsum.text! != "0"){
resultsum.text! += String(sender.tag)
}else{
resultsum.text! = String(sender.tag)
}
input = (resultsum.text! as NSString).doubleValue
//获得数字并存储
isEq = false
isMinus = false
isControl = false
}
//小数点
@IBAction func touchPoint(_ sender: UIButton) {
resultsum.text! += "."
}
//负号
@IBAction func touchMinus(_ sender: UIButton) {
if (res == 0){
equal(sender)
res = -input
} else{
res = -res
}
resultsum.text = String(res)
isMinus = true
}
//等号
@IBAction func equal(_ sender: UIButton) {
switch(fh) {
case 1:
res = lastRes + input
case 2:
res = lastRes - input
case 3:
res = lastRes * input
case 4:
res = lastRes / input
default:
break
}
resultsum.text! = "\(res)"
lastRes = res
isEq = true
isControl = true
}
//删去
@IBAction func backC(_ sender: UIButton) {
if resultsum.text?.count == 1 {
resultsum.text = "0"
}
else if (resultsum.text! as NSString).doubleValue != 0 {
resultsum.text?.removeLast()
}
input = (resultsum.text! as NSString).doubleValue
}
//加减乘除
@IBAction func getsign(_ sender: UIButton){
if sender.tag < 5 {
resultsum.text! = Priority[sender.tag - 1]
if isEq {
lastRes = res
}
else {
lastRes = input
}
}
fh = sender.tag
isControl = true
}
//清空
@IBAction func touchClean(_ sender: UIButton) {
res = 0
lastRes = 0
input = 0
resultsum.text = "0"
isControl = false
}
//其他运算
@IBAction func touchMath(_ sender: UIButton) {
math = sender.tag
if(res == 0){
res = input
}
switch(math){
case 7:
res = res * 3.14
case 8:
res = res * res
case 9:
res = sin(res)
case 10:
res = cos(res)
default:
break
}
resultsum.text! = "\(res)"
lastRes = res
isEq = true
}
}
所有源码下载
csdn下载点【这儿】 百度云下载点【这儿】提取码 2333
总结
本项目完结了一个精约易用的多功用备忘录,可以帮助你随时随地为所欲为的记载你的事物,让你不在忘掉重要事项!一起,在记载的进程中必定有一些需求核算的当地,因而咱们还加入了核算器功用,让你可以直接进行核算,便利日子。不仅如此,若你的事物许多,那看着必定心烦意乱,因而我规划了“轻松一下功用”,可以让你在烦躁的时分听听音乐轻松一下,若心情急躁还可以采用慢速播映,反之可以快速播映,十分人性化的让你记载日子中的点点滴滴。 在该项目中,经过完结精约有用的多功用备忘录,对更多的IOS开发知识有你了愈加深化的了解。一起,在项目的进行进程中也呈现的许多的挫折,例如一些按钮的相关呈现了问题导致跳转过错、一些控件的某些参数改错了导致无法正确运转、数据持久化进程中无法正确存储等等。 但是经过不断的努力学习与互联网东西和老师同学的辅导,逐步处理了这些问题,最终让项目完整的呈现出来。从中深入的领会到了相互交流与向他人学习的重要性,今后会愈加努力的学习更多知识。