Last active
October 2, 2016 08:41
-
-
Save fumiyasac/c998fb9cfd267d79e9bd68c758638992 to your computer and use it in GitHub Desktop.
iPhoneアプリでUIを作るためのTipsとContainerView・UIPageViewControllerを使ったサンプル紹介 ref: http://qiita.com/fumiyasac@github/items/1244abc8e3286c47ef50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//スクロールが発生した際に行われる処理 | |
func scrollViewDidScroll(scrollview: UIScrollView) { | |
//コンテンツのスクロールのみ検知 | |
if scrollview.tag == ScrollViewTag.MainScroll.returnValue() { | |
//現在表示されているページ番号を判別する | |
let pageWidth: CGFloat = self.mainScrollView.frame.width | |
let fractionalPage: Double = Double(self.mainScrollView.contentOffset.x / pageWidth) | |
let page: NSInteger = lround(fractionalPage) | |
//ボタン配置用のスクロールビューもスライドさせる | |
self.moveFormNowButtonContentsScrollView(page) | |
self.moveToCurrentButtonLabel(page) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ハンバーガーボタンを押下した際のアクション | |
@IBAction func viewControllerOpen(sender: AnyObject) { | |
let viewController = self.parentViewController as! ViewController | |
viewController.judgeSideContainer(SideStatus.Opened) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//サイドのコンテナビューに関するenum | |
enum SideStatus { | |
case Opened | |
case Closed | |
} | |
//定数設定などその他 | |
struct BaseSettings { | |
//ScrollViewのサイズに関するセッテイング | |
static let movedButtonX : Int = 268 | |
static let closedButtonX : Int = 0 | |
//ScrollViewのサイズに関するセッテイング | |
static let movedMainX : Int = 280 | |
static let closedMainX : Int = 0 | |
} | |
/** | |
* ↓↓↓↓↓ ※下記のメソッドはクラス内の記述になります ↓↓↓↓↓ | |
*/ | |
//ステータスに応じてメインコンテナの開閉を決定する | |
func judgeSideContainer(status: SideStatus) { | |
if status == SideStatus.Closed { | |
UIView.animateWithDuration(0.13, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { | |
self.mainContainer.frame = CGRectMake( | |
CGFloat(BaseSettings.closedMainX), | |
CGFloat(self.mainContainer.frame.origin.y), | |
CGFloat(self.mainContainer.frame.width), | |
CGFloat(self.mainContainer.frame.height) | |
) | |
self.hiddenButton.frame = CGRectMake( | |
CGFloat(BaseSettings.closedButtonX), | |
CGFloat(self.mainContainer.frame.origin.y), | |
CGFloat(self.mainContainer.frame.width), | |
CGFloat(self.mainContainer.frame.height) | |
) | |
self.hiddenButton.alpha = 0 | |
}, completion: { finished in | |
self.hiddenButton.enabled = false | |
}) | |
} else { | |
UIView.animateWithDuration(0.13, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { | |
self.mainContainer.frame = CGRectMake( | |
CGFloat(BaseSettings.movedMainX), | |
CGFloat(self.mainContainer.frame.origin.y), | |
CGFloat(self.mainContainer.frame.width), | |
CGFloat(self.mainContainer.frame.height) | |
) | |
self.hiddenButton.frame = CGRectMake( | |
CGFloat(BaseSettings.movedButtonX), | |
CGFloat(self.mainContainer.frame.origin.y), | |
CGFloat(self.mainContainer.frame.width), | |
CGFloat(self.mainContainer.frame.height) | |
) | |
self.hiddenButton.alpha = 0.6 | |
}, completion: { finished in | |
self.hiddenButton.enabled = true | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment