Class: CameraController
- Inherits:
-
AVClubController
- Object
- UIViewController
- AVClubController
- CameraController
- Defined in:
- app/camera_controller.rb
Instance Attribute Summary collapse
-
#record_button ⇒ Object
Returns the value of attribute record_button.
-
#still_button ⇒ Object
Returns the value of attribute still_button.
-
#toggle_button ⇒ Object
Returns the value of attribute toggle_button.
Attributes inherited from AVClubController
Instance Method Summary collapse
- #capture_still_image(sender) ⇒ Object
- #club(club, assetSavedToURL: image, error: error) ⇒ Object
- #clubDeviceConfigurationChanged(club) ⇒ Object
- #clubRecordingBegan(club) ⇒ Object
- #clubRecordingFinished(club) ⇒ Object
-
#tap_to_auto_focus(gesture_recognizer) ⇒ Object
Auto focus at a particular point.
-
#tapToContinouslyAutoFocus(gesture_recognizer) ⇒ Object
Change to continuous auto focus.
- #toggle_camera(sender) ⇒ Object
- #toggle_recording(sender) ⇒ Object
- #update_button_states ⇒ Object
- #viewDidLoad ⇒ Object
- #willRotateToInterfaceOrientation(to_interface_duration, duration: duration) ⇒ Object
Methods inherited from AVClubController
#rotate_camera_to, #start_in_view
Instance Attribute Details
#record_button ⇒ Object
Returns the value of attribute record_button.
2 3 4 |
# File 'app/camera_controller.rb', line 2 def @record_button end |
#still_button ⇒ Object
Returns the value of attribute still_button.
2 3 4 |
# File 'app/camera_controller.rb', line 2 def @still_button end |
#toggle_button ⇒ Object
Returns the value of attribute toggle_button.
2 3 4 |
# File 'app/camera_controller.rb', line 2 def @toggle_button end |
Instance Method Details
#capture_still_image(sender) ⇒ Object
116 117 118 119 120 121 122 |
# File 'app/camera_controller.rb', line 116 def capture_still_image(sender) return unless .isEnabled # Capture a still image .enabled = false club.captureStillImageAnimated(true) end |
#club(club, assetSavedToURL: image, error: error) ⇒ Object
157 158 159 160 161 162 163 |
# File 'app/camera_controller.rb', line 157 def club(club, stillImageCaptured:image, error:error) if image club.saveImageToLibrary(image) else end end |
#clubDeviceConfigurationChanged(club) ⇒ Object
169 170 171 |
# File 'app/camera_controller.rb', line 169 def clubDeviceConfigurationChanged(club) end |
#clubRecordingBegan(club) ⇒ Object
147 148 149 150 |
# File 'app/camera_controller.rb', line 147 def clubRecordingBegan(club) self..setTitle('Stop', forState:UIControlStateNormal) end |
#clubRecordingFinished(club) ⇒ Object
152 153 154 155 |
# File 'app/camera_controller.rb', line 152 def clubRecordingFinished(club) self..setTitle('Record', forState:UIControlStateNormal) end |
#tap_to_auto_focus(gesture_recognizer) ⇒ Object
Auto focus at a particular point. The focus mode will remain locked.
78 79 80 81 82 83 84 85 86 |
# File 'app/camera_controller.rb', line 78 def tap_to_auto_focus(gesture_recognizer) return unless club.videoInput if club.videoInput.device.isFocusPointOfInterestSupported tapPoint = gesture_recognizer.locationInView(gesture_recognizer.view) convertedFocusPoint = club.convertToPointOfInterestFromViewCoordinates(tapPoint) club.autoFocusAtPoint(convertedFocusPoint) end end |
#tapToContinouslyAutoFocus(gesture_recognizer) ⇒ Object
Change to continuous auto focus. The camera will focus at the point choosen, and then continue to auto focus.
90 91 92 93 94 95 96 |
# File 'app/camera_controller.rb', line 90 def tapToContinouslyAutoFocus(gesture_recognizer) return unless club.videoInput if club.videoInput.device.isFocusPointOfInterestSupported club.continuousFocusAtPoint(CGPoint.new(0.5, 0.5)) end end |
#toggle_camera(sender) ⇒ Object
98 99 100 101 102 103 104 |
# File 'app/camera_controller.rb', line 98 def toggle_camera(sender) # Toggle between cameras when there is more than one club.toggleCamera # Do an initial focus club.continuousFocusAtPoint(CGPoint.new(0.5, 0.5)) end |
#toggle_recording(sender) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'app/camera_controller.rb', line 106 def toggle_recording(sender) # Start recording if there isn't a recording running. Stop recording if there is. .enabled = false unless club.recorder.isRecording club.startRecording else club.stopRecording end end |
#update_button_states ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/camera_controller.rb', line 124 def if club.cameraCount > 1 self..enabled = true self..enabled = true self..enabled = true else self..enabled = false if club.cameraCount > 0 self..enabled = true self..enabled = true else self..enabled = false if club.micCount > 0 self. = true else self. = false end end end end |
#viewDidLoad ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/camera_controller.rb', line 4 def viewDidLoad super self.view.backgroundColor = UIColor.darkGrayColor view_finder = UIView.alloc.initWithFrame(UIEdgeInsetsInsetRect(self.view.bounds, [50, 20, 20, 20])) view_finder.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth view_finder.backgroundColor = UIColor.lightGrayColor self.view.addSubview(view_finder) ### important ### start_in_view(view_finder) width = 0 height = 0 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Camera', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) height = CGRectGetHeight(.frame) .addTarget(self, action: 'toggle_camera:', forControlEvents:UIControlEventTouchUpInside) end width += 10 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Record', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) .addTarget(self, action: 'toggle_recording:', forControlEvents:UIControlEventTouchUpInside) end width += 10 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Photo', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) .addTarget(self, action: 'capture_still_image:', forControlEvents:UIControlEventTouchUpInside) end left = (CGRectGetWidth(self.view.frame) - width) / 2.0 top = 5 = UIView.alloc.initWithFrame([[left, top], [width, height]]) .autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin left = 0 top = 0 self..frame = [[left, top], self..frame.size] left += CGRectGetWidth(self..frame) + 10 self..frame = [[left, top], self..frame.size] left += CGRectGetWidth(self..frame) + 10 self..frame = [[left, top], self..frame.size] left += CGRectGetWidth(self..frame) + 10 .addSubview(self.) .addSubview(self.) .addSubview(self.) self.view.addSubview() self. # Add a single tap gesture to focus on the point tapped, then lock focus singleTap = UITapGestureRecognizer.alloc.initWithTarget(self, action:'tap_to_auto_focus:') singleTap.setDelegate(self) singleTap.setNumberOfTapsRequired(1) view_finder.addGestureRecognizer(singleTap) end |
#willRotateToInterfaceOrientation(to_interface_duration, duration: duration) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'app/camera_controller.rb', line 173 def willRotateToInterfaceOrientation(to_interface_duration, duration:duration) super case to_interface_duration when UIInterfaceOrientationLandscapeLeft new_frame = CGRect.new([0, 0], [480, 320]) when UIInterfaceOrientationLandscapeRight new_frame = CGRect.new([0, 0], [480, 320]) when UIInterfaceOrientationPortrait new_frame = CGRect.new([0, 0], [320, 480]) when UIInterfaceOrientationPortraitUpsideDown new_frame = CGRect.new([0, 0], [320, 480]) end ### important ### rotate_camera_to(new_frame, orientation:to_interface_duration, duration:duration) end |