swift2.0仿微信界面,可滑動cell,自定義圖片選擇器:LGWeChatKit
LGWeChatKit
swift2.0仿微信界面,可滑動cell,自定義圖片選擇器。。。
說明
LGWeChatKit是我再學習swift的過程中慢慢修改的,對于很多swift的編程特性還有很多不了解的地方,所以再代碼里面可能看到一些和OC類似的代碼形式 ,希望有什么不足的地方大家幫忙提出,如果你喜歡的話,請給個大大的Star吧,點下右上角就可以啦~謝謝啦~~
QQ群
創建一個swift技術討論群,歡迎各位大神加入交流 469492027
note
請在xcode7、IOS9.0以上版本上運行此程序demo,否則會有一些錯誤提示~~
feature
- 代碼基于swift2.0實現,包括很多swift的新用法,界面全部采用autolayout布局;
- 主要實現消息列表和聊天界面;
- 消息列表界面支持左右滑動,里面的內容可以定制;
- 聊天界面支持文本,語音,圖片等消息,文本消息可以刪除,復制等;
- 訪問系統相冊功能,基于新的PHoto.framework實現,界面和微信類似。
- 支持地圖調用;
- 使用新的Contacts.framework訪問通訊錄;
-
支持掃一掃的功能。
消息列表
再使用的時候,只要繼承LGConversionListBaseCell就可以了。
var cell = tableView.dequeueReusableCellWithIdentifier("messageListCell") as? LGConversionListCell if cell == nil { let leftButtons = [UIButton.createButton("取消關注", backGroundColor: UIColor.purpleColor())] let rightButtons = [UIButton.createButton("標記已讀", backGroundColor: UIColor.grayColor()),UIButton.createButton("刪除", backGroundColor: UIColor.redColor())] cell = LGConversionListCell(style: .Subtitle, reuseIdentifier: "messageListCell") cell?.delegate = self cell?.viewModel = updateCell() cell?.setLeftButtons(leftButtons) cell?.setRightButtons(rightButtons) } return cell!
系統相冊訪問
基于新的photo.framework,告別繁瑣的asset操作,使用起來非常的方便
獲取相冊流,包括自定義的文件夾
func getCollectionList() { let albumOptions = PHFetchOptions() albumOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)] let userAlbum = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .AlbumRegular, options: nil) userAlbum.enumerateObjectsUsingBlock { (collection, index, stop) -> Void in let coll = collection as! PHAssetCollection let assert = PHAsset.fetchAssetsInAssetCollection(coll, options: nil) if assert.count > 0 { let model = PHRootModel(title: coll.localizedTitle!, count: assert.count, fetchResult: assert) self.collections.value.append(model) } } let userCollection = PHCollectionList.fetchTopLevelUserCollectionsWithOptions(nil) userCollection.enumerateObjectsUsingBlock { (list, index, stop) -> Void in let list = list as! PHAssetCollection let assert = PHAsset.fetchAssetsInAssetCollection(list, options: nil) if assert.count > 0 { let model = PHRootModel(title: list.localizedTitle!, count: assert.count, fetchResult: assert) self.collections.value.append(model) } } }
獲取每一張圖片,options是可選屬性,可以設置圖片的質量等
PHImageManager.defaultManager().requestImageForAsset(collection?.fetchResult.lastObject as! PHAsset, targetSize: CGSizeMake(50, 60), contentMode: .AspectFit, options: nil) { (image, _: [NSObject : AnyObject]?) -> Void in if image == nil { return } cell?.imageView?.image = image self.tableView.reloadData() }
聊天界面
支持錄音播放功能~
文本輸入
支持文字粘貼復制等功能
let pressIndexPath = tableView.indexPathForRowAtPoint(gestureRecognizer.locationInView(tableView))! tableView.selectRowAtIndexPath(pressIndexPath, animated: false, scrollPosition: .None) let menuController = UIMenuController.sharedMenuController() let localImageView = gestureRecognizer.view! menuController.setTargetRect(localImageView.frame, inView: localImageView.superview!) menuController.menuItems = [UIMenuItem(title: "復制", action: "copyAction:"), UIMenuItem(title: "轉發", action: "transtionAction:"), UIMenuItem(title: "刪除", action: "deleteAction:"), UIMenuItem(title: "更多", action: "moreAciton:")] menuController.setMenuVisible(true, animated: true)
獲取通訊錄
使用Contacts.framework,該功能再IOS9以上可以使用!
let store = CNContactStore() let keyToFetch = [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName), CNContactImageDataKey, CNContactPhoneNumbersKey] let fetchRequest = CNContactFetchRequest(keysToFetch: keyToFetch) var contacts = [CNContact]() do { try store.enumerateContactsWithFetchRequest(fetchRequest, usingBlock: { (contact, stop) -> Void in contacts.append(contact) }) } catch let error as NSError { print(error.localizedDescription) }
掃描
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!