motion-gyro-image-controller 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmY3ZGM0NDAzNTVkMzIwOGZkZGU1ZDhlMTU4OGFkODk5YTY5ODUyNQ==
5
+ data.tar.gz: !binary |-
6
+ YTI5OGNjZjlhNTMzOGY4ODE5ZWQ4NTVkMzdjZjdlNDI4NzVlZDMwZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2ViMTBiYzFjM2VjMzc3OGI1MzlmNzg0ODM2N2FjZDU5N2VhODA0YjQwODA2
10
+ OWM5YmVjN2Y2ZGY2NmE5NzQyMWQ2N2JiNGZhMjQ2OTliZjk2MDBjNTJlMDM5
11
+ MzQzZWY0NTI4Y2UyYjQyNDNkMDU4ZGE1NTEzODlmYmU2ZmNlMGQ=
12
+ data.tar.gz: !binary |-
13
+ ZmUxOGUwMzE4ODlhYmMzODViYTUzOTE4YWFhODg0N2UzOWIzNjNhZGI2ZTAw
14
+ YWQyYTRiZDBlNzExZTQ5MTg1ODQwYTlkZDdhM2VjMWYwYzFhMWRmNmIyZGFm
15
+ YWIwNDQ1MzQ2NmVkMzYzYTIyNjMyMDBmYzhjMGQ4YmMzMDc3MzM=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in motion-gyro-image-controller.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Multunus Software Pvt Ltd
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Motion::Gyro::Image::Controller
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'motion-gyro-image-controller'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install motion-gyro-image-controller
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/motion-gyro-image-controller/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ Dir.glob(File.join(File.dirname(__FILE__), "motion-gyro-image-controller/*.rb")).each do |file|
7
+ app.files.unshift(file)
8
+ end
9
+ end
@@ -0,0 +1,97 @@
1
+ class GyroDrivenImageViewController < ScrollingImageViewController
2
+ attr_accessor :update_interval, :shake_threshold, :motion_rate
3
+
4
+ def viewDidLoad
5
+ super
6
+ @motion_manager = CMMotionManager.alloc.init
7
+ end
8
+
9
+ def viewDidAppear animated
10
+ super
11
+ setup_gyro if gyro_available
12
+ end
13
+
14
+ def viewWillDisappear(animated)
15
+ super
16
+ teardown_gyro if gyro_available
17
+ end
18
+
19
+ def gyro_available
20
+ @motion_manager.isGyroAvailable
21
+ end
22
+
23
+ def significant_tilt
24
+ @motion_manager.deviceMotion.rotationRate.y.abs >= self.shake_threshold
25
+ end
26
+
27
+ def device_motion_available
28
+ @motion_manager.deviceMotion
29
+ end
30
+
31
+ def setup_gyro
32
+ initialize_gyro_setup
33
+ activate_timer_control
34
+ end
35
+
36
+ def initialize_gyro_setup
37
+ @motion_manager.showsDeviceMovementDisplay = true
38
+ @motion_manager.deviceMotionUpdateInterval = self.update_interval
39
+ @motion_manager.startDeviceMotionUpdates
40
+ end
41
+
42
+ def teardown_gyro
43
+ @timer.cancel!
44
+ @motion_manager.stopDeviceMotionUpdates
45
+ end
46
+
47
+ def activate_timer_control
48
+ queue = Dispatch::Queue.current
49
+ @timer = Dispatch::Source.timer(self.update_interval, self.update_interval, 0.0, queue) do |source|
50
+ begin
51
+ periodic_timer
52
+ ensure
53
+ # source.cancel!
54
+ end
55
+ end
56
+ end
57
+
58
+ def periodic_timer
59
+ if gyro_requirements_met? && content_exceeds_available_space?
60
+ roll = @motion_manager.deviceMotion.rotationRate.y * self.motion_rate
61
+ if roll > 0
62
+ new_offset = get_scroll_offset_towards_left roll
63
+ elsif roll < 0
64
+ new_offset = get_scroll_offset_towards_right roll
65
+ end
66
+ @scroll_view.setContentOffset([new_offset, @scroll_view.contentOffset.y], animated: false)
67
+ end
68
+ end
69
+
70
+ def get_scroll_offset_towards_left roll
71
+ current_offset = @scroll_view.contentOffset.x
72
+ new_offset = current_offset - (current_offset * roll)
73
+ new_offset = 0 if new_offset < 0
74
+ new_offset
75
+ end
76
+
77
+ def get_scroll_offset_towards_right roll
78
+ current_offset = @scroll_view.contentOffset.x
79
+ width = @scroll_view.contentSize.width - Device.screen.width
80
+ new_offset = current_offset - ((width - current_offset) * roll)
81
+ new_offset = width if new_offset > width
82
+ new_offset
83
+ end
84
+
85
+ def gyro_requirements_met?
86
+ device_motion_available && significant_tilt && @scroll_view
87
+ end
88
+
89
+ def content_exceeds_available_space?
90
+ @scroll_view.contentSize.width > self.width
91
+ end
92
+
93
+ def fit_image_to_height
94
+ super
95
+ setup_gyro if gyro_available
96
+ end
97
+ end
@@ -0,0 +1,41 @@
1
+ class ScrollingImageViewController < UIViewController
2
+ attr_accessor :index, :width, :height
3
+
4
+ def set_up_view(width, height)
5
+ self.width = width
6
+ self.height = height
7
+ @scroll_view = set_up_scroll_view
8
+ @image_view = set_up_image_view
9
+ @scroll_view.addSubview(@image_view)
10
+ self.view.addSubview(@scroll_view)
11
+ end
12
+
13
+ def set_up_scroll_view
14
+ scroll_view = UIScrollView.alloc.initWithFrame(CGRectMake(0, 0, self.width, self.height))
15
+ scroll_view.showsHorizontalScrollIndicator = false
16
+ scroll_view.showsVerticalScrollIndicator = false
17
+ scroll_view.delegate = self
18
+ scroll_view.scrollEnabled = false
19
+ scroll_view
20
+ end
21
+
22
+ def set_up_image_view
23
+ image_view = UIImageView.alloc.initWithFrame(CGRectMake(0, 0, self.width, self.height))
24
+ image_view.contentMode = UIViewContentModeScaleToFill
25
+ image_view
26
+ end
27
+
28
+ def set_image image
29
+ @image_view.image = image
30
+ fit_image_to_height
31
+ end
32
+
33
+ def fit_image_to_height
34
+ final_height = self.view.size.height
35
+ final_width = (@image_view.image.size.width / @image_view.image.size.height) * final_height
36
+ scroll_offset = (final_width - self.width) / 2
37
+ @image_view.frame = CGRectMake(0, 0, final_width, final_height)
38
+ @scroll_view.contentSize = CGSizeMake(final_width, final_height)
39
+ @scroll_view.setContentOffset(CGPointMake(scroll_offset, 0), animated: false)
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "motion-gyro-image-controller"
7
+ spec.version = "1.0"
8
+ spec.authors = ["Multunus"]
9
+ spec.email = ["info@multunus.com"]
10
+ spec.summary = %q{A controller that lets you control images using gyro}
11
+ spec.description = %q{RubyMotion image view controller that lets you preview images by means of tilt}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-gyro-image-controller
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Multunus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: RubyMotion image view controller that lets you preview images by means
42
+ of tilt
43
+ email:
44
+ - info@multunus.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/motion-gyro-image-controller.rb
55
+ - lib/motion-gyro-image-controller/gyro_driven_image_view_controller.rb
56
+ - lib/motion-gyro-image-controller/scrolling_image_view_controller.rb
57
+ - motion-gyro-image-controller.gemspec
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A controller that lets you control images using gyro
82
+ test_files: []