mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
143 lines
4.7 KiB
Swift
143 lines
4.7 KiB
Swift
//
|
|
// ProfileViewController.swift
|
|
// librx
|
|
//
|
|
// Created by Yunlong Zheng on 15/8/5.
|
|
// Copyright (c) 2015年 librx. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class ProfileViewController: UIViewController{
|
|
|
|
@IBOutlet weak var nameLabel: UILabel!
|
|
@IBOutlet weak var subTitleLabel: UILabel!
|
|
@IBOutlet weak var followNumLabel: UILabel!
|
|
@IBOutlet weak var followerNumLabel: UILabel!
|
|
@IBOutlet weak var follosNumLabel: UILabel!
|
|
@IBOutlet weak var avatarImageView: UIImageView!
|
|
@IBOutlet weak var contentView: UIView!
|
|
@IBOutlet weak var followButton: UIButton!
|
|
|
|
private var containerViewController: ContainerViewController!
|
|
private var screenSize: CGRect!
|
|
private var screenWidth: CGFloat!
|
|
private var screenHeight: CGFloat!
|
|
|
|
// 其他用户个人中心
|
|
var isMe:Bool = true
|
|
var userId:Int?
|
|
|
|
var lastOffsetY :CGFloat = 0
|
|
|
|
private var loginAction : LoginAction?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
|
|
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
|
|
|
|
screenSize = UIScreen.mainScreen().bounds
|
|
screenWidth = screenSize.width
|
|
screenHeight = screenSize.height
|
|
|
|
self.avatarImageView.layer.cornerRadius = self.avatarImageView.frame.width / 2
|
|
self.avatarImageView.clipsToBounds = true
|
|
self.avatarImageView.layer.borderWidth = 2
|
|
self.avatarImageView.layer.borderColor = UIColor.whiteColor().CGColor
|
|
|
|
self.followButton.layer.borderWidth = 1
|
|
self.followButton.layer.borderColor = UIColor.whiteColor().CGColor
|
|
|
|
navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
|
|
navigationController?.navigationBar.tintColor = UIColor.whiteColor()
|
|
|
|
navigationController?.navigationBar.backItem?.hidesBackButton = false
|
|
|
|
}
|
|
|
|
override func viewDidAppear(animated: Bool) {
|
|
|
|
super.viewDidDisappear(animated)
|
|
if self.isMe {
|
|
loadMeProfile()
|
|
} else{
|
|
loadUserProfile(userId!)
|
|
print(">>>> \(LocalStore.accessUserId())")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func loadUserProfile(userId: Int){
|
|
|
|
LibrxService.profile(userId) { [weak self](profile) -> () in
|
|
|
|
if let selfView = self {
|
|
let avatar = NSURL(string: profile.avatar)
|
|
selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default"))
|
|
selfView.nameLabel.text = profile.name
|
|
selfView.subTitleLabel.text = "简介:\(profile.email)"
|
|
selfView.followerNumLabel.text = String(profile.followersCount)
|
|
selfView.follosNumLabel.text = String(profile.followsCount)
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func loadMeProfile(){
|
|
|
|
if let _ = LocalStore.accessToken() {
|
|
LibrxService.me { [weak self](profile) -> () in
|
|
|
|
if let selfView = self {
|
|
let avatar = NSURL(string: profile.avatar)
|
|
selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default"))
|
|
selfView.nameLabel.text = profile.name
|
|
selfView.subTitleLabel.text = "简介:\(profile.email)"
|
|
selfView.followerNumLabel.text = String(profile.followersCount)
|
|
selfView.follosNumLabel.text = String(profile.followsCount)
|
|
}
|
|
|
|
}
|
|
}else{
|
|
loginAction = LoginAction(viewController: self, completion: { [weak self]() -> () in
|
|
if let strongSelf = self {
|
|
strongSelf.dismissViewControllerAnimated(true, completion: nil)
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@IBAction func unwindToProfile(segue: UIStoryboardSegue) {
|
|
|
|
}
|
|
|
|
|
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
|
|
|
if segue.identifier == "containerSegue" {
|
|
self.containerViewController = segue.destinationViewController as! ContainerViewController
|
|
self.containerViewController.isMe = isMe
|
|
self.containerViewController.userId = userId
|
|
}
|
|
|
|
}
|
|
|
|
|
|
@IBAction func segmentSwicth(sender: UISegmentedControl) {
|
|
self.containerViewController.turnToPage(sender.selectedSegmentIndex)
|
|
|
|
}
|
|
}
|
|
|
|
extension ProfileViewController: UIScrollViewDelegate{}
|
|
extension ProfileViewController: UIPageViewControllerDelegate{}
|
|
|
|
|
|
|