-
-
Save colinta/5371964 to your computer and use it in GitHub Desktop.
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
Teacup::Stylesheet.new :create_screen do | |
# Input Fields | |
style :input_text_wrapper, | |
left: 24, | |
backgroundColor: UIColor.colorWithPatternImage(UIImage.imageNamed('ui-textfield-normal.png')), | |
userInteractionEnabled: true, | |
width: 249 | |
style :input_text_type, | |
extends: :input_text_wrapper, | |
top: 50 | |
style :input_text_name, | |
extends: :input_text_wrapper, | |
constraints: [ | |
constrain(:top).equals(:input_text_type, :bottom).plus(15) | |
] | |
style :input_text_location, | |
extends: :input_text_wrapper, | |
constraints: [ | |
constrain(:top).equals(:input_text_name, :bottom).plus(15) | |
] | |
style :input_text, | |
color: BubbleWrap.rgb_color(118, 90, 59), | |
height: 21, | |
left: 8, | |
placeholder: 'Nothing Set', | |
top: 5, | |
width: 237 | |
style :challenge_type, | |
extends: :input_text, | |
placeholder: 'Challenge Type' | |
style :challenge_name, | |
extends: :input_text, | |
placeholder: 'Name of the Challenge' | |
style :challenge_location, | |
extends: :input_text, | |
placeholder: 'Start Location' | |
end |
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 CreateViewController < UIViewController | |
include GM::KeyboardHandler | |
stylesheet :create_screen | |
# Create our parent declarations, instantiate, and set properties | |
def loadView | |
self.view = UIScrollView.new | |
# A nice handy function from @colinta which will intercept our keyboard delegation | |
# and do work for us, like making the scroll area larger to accommodate overlap and such | |
prepare_keyboard_handler(self.view) | |
end | |
# I still need to figure out if it's going to be best to leave this logic here, | |
# where I create multiple child views and attach them to @pagination ... OR if | |
# these should be moved out into their own controllers.. but then how will | |
# keyboard delegation and other master -> child properties get passed? | |
layout :root do | |
# assign our input fields to an array so we can loop through | |
# and manage keyboard actions | |
@input_fields = [] | |
subview(UIView, :input_text_type) do | |
@input_fields << subview(UITextField, :challenge_type) | |
end | |
subview(UIImageView, :input_text_name) do | |
@input_fields << subview(UITextField, :challenge_name) | |
end | |
subview(UIImageView, :input_text_location) do | |
@input_fields << subview(UITextField, :challenge_location) | |
end | |
# if this is in viewWillAppear, it will be called everytime the view is | |
# shown - the delegate need not be reassigned (no side effects in this | |
# case, but putting setup code in viewWillAppear can be a bad habit to | |
# shake) | |
@input_fields.each { |field| | |
field.delegate = self | |
} | |
# in this case there *would* be a side effect, but no one would notice - | |
# resignFirstResponder would be called many times | |
self.view.when_tapped do | |
@input_fields.each { |field| | |
field.resignFirstResponder | |
} | |
end | |
end | |
# As the view is actually being called, lets attach our listeners | |
def viewWillAppear(animated) | |
super | |
keyboard_handler_start | |
end | |
# Remove the keyboard listener | |
def viewWillDisappear(animated) | |
super | |
keyboard_handler_stop | |
end | |
def textFieldShouldReturn(textfield) | |
index = @input_fields.index(textfield) | |
if index == @input_fields.length - 1 | |
textfield.resignFirstResponder | |
else | |
@input_fields[index + 1].becomeFirstResponder | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment