Skip to content

Instantly share code, notes, and snippets.

@burhanaksendir
Created July 9, 2015 12:03
Show Gist options
  • Save burhanaksendir/8b5f88e96290dc7117c1 to your computer and use it in GitHub Desktop.
Save burhanaksendir/8b5f88e96290dc7117c1 to your computer and use it in GitHub Desktop.
Açılıp Kapanan Yan Menü :)
//
// ViewController.swift
// SideMenu
//
// Created by Burhan Aksendir on 9.07.2015.
// Copyright (c) 2015 Aksendir. All rights reserved.
//
import UIKit
enum MenuDurumu {
case Acik
case Kapali
}
class ViewController: UIViewController {
var menuButonu: UIBarButtonItem!
var menuDurumu: MenuDurumu = .Kapali {
didSet {
golgeEkle((menuDurumu == .Acik))
}
}
var sideVC: SideViewController?
let menuMarginX: CGFloat = 99
override func viewDidLoad() {
super.viewDidLoad()
let imageView = UIImageView(image: UIImage(named: "kitten_1")!)
imageView.frame = self.view.bounds
imageView.contentMode = UIViewContentMode.ScaleAspectFill
self.view.addSubview(imageView)
menuButonu = UIBarButtonItem(title: "AçKapa", style: UIBarButtonItemStyle.Plain, target: self, action: "menuyuAc")
self.navigationItem.rightBarButtonItem = menuButonu
}
func menuyuAc() {
let acik = (menuDurumu == .Acik)
if !acik {
viewControllerEkle()
}
menuAnimasyonu((acik == false))
}
func viewControllerEkle() {
if(sideVC == nil) {
sideVC = SideViewController()
// İŞTE TAM BURADA HATA YAPIYORUM ÇÜNKÜ EKLENMİYOR.
//Ben istiyorum ki o siyah alana bu sideVC gelsin.
view.insertSubview(sideVC!.view, atIndex: 0)
self.addChildViewController(sideVC!)
sideVC!.didMoveToParentViewController(self)
}
}
func menuAnimasyonu(uygula: Bool) {
if(uygula) {
menuDurumu = MenuDurumu.Acik
menuyuKaydir(xPosizyonu: CGRectGetWidth(self.view.frame) - menuMarginX)
} else {
menuyuKaydir(xPosizyonu: 0) { finished in
self.menuDurumu = MenuDurumu.Kapali
self.sideVC!.view.removeFromSuperview()
self.sideVC = nil
}
}
}
func menuyuKaydir(#xPosizyonu:CGFloat, completion: ((Bool) -> Void)! = nil) {
UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.navigationController!.view.frame.origin.x = -xPosizyonu
}, completion: completion)
}
func golgeEkle(uygula: Bool) {
if uygula {
self.navigationController!.view.layer.shadowOpacity = 0.8
} else {
self.navigationController!.view.layer.shadowOpacity = 0
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment