Created
July 14, 2014 09:00
-
-
Save winnie2012/3672c476b2e9d8478493 to your computer and use it in GitHub Desktop.
ProMotion + Motion-Layout
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
source "https://rubygems.org" | |
gem "rake" | |
# Screens | |
gem "ProMotion" | |
gem 'motion-layout' |
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
class HomeScreen < PM::Screen | |
title "Home" | |
def on_load | |
# After view is first loaded | |
set_nav_bar_button :right, title: "Help", action: :show_help | |
@state = UILabel.new | |
@state.font = UIFont.systemFontOfSize(30) | |
@state.text = 'Tap to start' | |
@state.textAlignment = UITextAlignmentCenter | |
@state.textColor = UIColor.whiteColor | |
@state.backgroundColor = UIColor.clearColor | |
@action = UIButton.buttonWithType(UIButtonTypeRoundedRect) | |
@action.setTitle('Start', forState:UIControlStateNormal) | |
@action.setTitle('Stop', forState:UIControlStateSelected) | |
@action.addTarget(self, action:'actionTapped', forControlEvents:UIControlEventTouchUpInside) | |
Motion::Layout.new do |layout| | |
layout.view view | |
layout.subviews "state" => @state, "action" => @action | |
layout.metrics "top" => 200, "margin" => 20, "height" => 40 | |
layout.vertical "|-top-[state(==height)]-margin-[action(==height)]" | |
layout.horizontal "|-margin-[state]-margin-|" | |
layout.horizontal "|-margin-[action]-margin-|" | |
end | |
end | |
def actionTapped | |
if @timer | |
@timer.invalidate | |
@timer = nil | |
else | |
@duration = 0 | |
@timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self, selector:'timerFired', userInfo:nil, repeats:true) | |
end | |
@action.selected = [email protected]? | |
end | |
def timerFired | |
@state.text = "%.1f" % (@duration += 0.1) | |
end | |
def show_help | |
open HelpScreen | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good,回去试用一下