Last active
December 10, 2015 01:38
-
-
Save amazedkoumei/4360773 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
# -*- coding: utf-8 -*- | |
class InformView < UIView | |
WIDTH = 280 | |
HEIGHT = 100 | |
# singleton | |
def self.instance | |
# warning at super in "init" method --version 1.29 > unknown: warning: passing a block to an Objective-C method - will be ignored | |
# Dispatch.once { @instance ||= new } | |
@instance = new if @instance.nil? | |
@instance | |
end | |
def self.show(message, target:view, animated:animated) | |
@instance = InformView.instance | |
@instance.removeFromSuperview() | |
view.addSubview(@instance) | |
@instance.instance_eval do | |
@label.text = message | |
@indicator.startAnimating() | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 1.0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 1.0 | |
end | |
end | |
end | |
def self.hide(animated) | |
return if @instance.nil? | |
@instance.instance_eval do | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 0 | |
end | |
@indicator.stopAnimating() | |
end | |
end | |
def init() | |
if super | |
x = (App.window.frame.size.width - WIDTH) / 2 | |
y = (App.window.frame.size.height - HEIGHT) / 2 - 50 | |
self.frame = [[x, y], [WIDTH, HEIGHT]] | |
self.backgroundColor = UIColor.colorWithWhite(0.0, alpha:0.5) | |
self.alpha = 1.0 | |
self.layer.cornerRadius = 8.0 | |
self.layer.masksToBounds = true | |
self.clipsToBounds = true | |
@label = UILabel.new.tap do |l| | |
l.frame = [[0, 60], [WIDTH, 30]] | |
l.textColor = UIColor.whiteColor | |
l.textAlignment = NSTextAlignmentCenter | |
l.font = UIFont.boldSystemFontOfSize(18.0) | |
l.alpha = 1.0 | |
l.backgroundColor = UIColor.clearColor | |
self.addSubview(l) | |
end | |
@indicator = UIActivityIndicatorView.new.tap do |i| | |
i.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhiteLarge) | |
i.frame = [[0, 10], [WIDTH, 50]] | |
i.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite | |
i.backgroundColor = UIColor.clearColor | |
self.addSubview(i) | |
end | |
InformView.hide(false) | |
end | |
self | |
end | |
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
# -*- coding: utf-8 -*- | |
class InformView < UIView | |
attr_accessor :message | |
def init() | |
if super | |
width = 280 | |
height = 100 | |
x = (App.window.frame.size.width - width) / 2 | |
y = (App.window.frame.size.height - height) / 2 - 50 | |
self.frame = CGRectMake(x , y, width, height) | |
self.backgroundColor = UIColor.colorWithWhite(0.0, alpha:0.5) | |
self.alpha = 1.0 | |
self.layer.cornerRadius = 8.0 | |
self.layer.masksToBounds = true | |
self.clipsToBounds = true | |
@message = message | |
@label = UILabel.new.tap do |l| | |
l.frame = CGRectMake(0 , 60, 280, 30) | |
l.textColor = UIColor.whiteColor | |
l.textAlignment = NSTextAlignmentCenter | |
l.font = UIFont.boldSystemFontOfSize(18.0) | |
l.alpha = 1 | |
l.backgroundColor = UIColor.clearColor | |
self.addSubview(l) | |
end | |
@indicator = UIActivityIndicatorView.new.tap do |i| | |
i.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhiteLarge) | |
i.frame = CGRectMake(0 , 10, 280, 50) | |
i.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite | |
i.backgroundColor = UIColor.clearColor | |
self.addSubview(i) | |
end | |
self.hideWithAnimation(false) | |
end | |
self | |
end | |
def showWithAnimation(animated) | |
@indicator.startAnimating() | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 1.0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 1.0 | |
end | |
end | |
def hideWithAnimation(animated) | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 0 | |
end | |
@indicator.stopAnimating() | |
end | |
def drawRect(rect) | |
super | |
@label.text = @message | |
end | |
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
# show view | |
InformView.show("loading..", target:navigationController.view, animated:true) | |
# hide view | |
InformView.hide(true) |
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
# show view | |
@informView = InformView.new.tap do |v| | |
v.message = "loading...") | |
navigationController.view.addSubview(v) | |
end | |
@informView.showWithAnimation(true) | |
# hide view | |
@informView.hideWithAnimation(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment