Skip to content

Instantly share code, notes, and snippets.

@winnie2012
Created July 14, 2014 09:00
Show Gist options
  • Save winnie2012/3672c476b2e9d8478493 to your computer and use it in GitHub Desktop.
Save winnie2012/3672c476b2e9d8478493 to your computer and use it in GitHub Desktop.
ProMotion + Motion-Layout
source "https://rubygems.org"
gem "rake"
# Screens
gem "ProMotion"
gem 'motion-layout'
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 = !@action.selected?
end
def timerFired
@state.text = "%.1f" % (@duration += 0.1)
end
def show_help
open HelpScreen
end
end
@easonhan007
Copy link

good,回去试用一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment