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
- #captureStillImage(sender) ⇒ Object
- #club(club, assetSavedToURL: image, error: error) ⇒ Object
- #clubDeviceConfigurationChanged(club) ⇒ Object
- #clubRecordingBegan(club) ⇒ Object
- #clubRecordingFinished(club) ⇒ Object
-
#tapToAutoFocus(gestureRecognizer) ⇒ Object
Auto focus at a particular point.
-
#tapToContinouslyAutoFocus(gestureRecognizer) ⇒ Object
Change to continuous auto focus.
- #toggleCamera(sender) ⇒ Object
- #toggleRecording(sender) ⇒ Object
- #update_button_states ⇒ Object
- #viewDidLoad ⇒ Object
- #willRotateToInterfaceOrientation(toInterfaceOrientation, duration: duration) ⇒ Object
Methods inherited from AVClubController
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
#captureStillImage(sender) ⇒ Object
118 119 120 121 122 123 124 |
# File 'app/camera_controller.rb', line 118 def captureStillImage(sender) return unless .isEnabled # Capture a still image .setEnabled(false) club.captureStillImageAnimated(true) end |
#club(club, assetSavedToURL: image, error: error) ⇒ Object
159 160 161 162 163 164 165 |
# File 'app/camera_controller.rb', line 159 def club(club, stillImageCaptured:image, error:error) if image club.saveImageToLibrary(image) else end end |
#clubDeviceConfigurationChanged(club) ⇒ Object
171 172 173 |
# File 'app/camera_controller.rb', line 171 def clubDeviceConfigurationChanged(club) end |
#clubRecordingBegan(club) ⇒ Object
149 150 151 152 |
# File 'app/camera_controller.rb', line 149 def clubRecordingBegan(club) self..setTitle('Stop', forState:UIControlStateNormal) end |
#clubRecordingFinished(club) ⇒ Object
154 155 156 157 |
# File 'app/camera_controller.rb', line 154 def clubRecordingFinished(club) self..setTitle('Record', forState:UIControlStateNormal) end |
#tapToAutoFocus(gestureRecognizer) ⇒ Object
Auto focus at a particular point. The focus mode will change to locked once the auto focus happens.
80 81 82 83 84 85 86 87 88 |
# File 'app/camera_controller.rb', line 80 def tapToAutoFocus(gestureRecognizer) return unless club.videoInput if club.videoInput.device.isFocusPointOfInterestSupported tapPoint = gestureRecognizer.locationInView(viewFinderView) convertedFocusPoint = club.convertToPointOfInterestFromViewCoordinates(tapPoint) club.autoFocusAtPoint(convertedFocusPoint) end end |
#tapToContinouslyAutoFocus(gestureRecognizer) ⇒ Object
Change to continuous auto focus. The camera will constantly focus at the point choosen.
92 93 94 95 96 97 98 |
# File 'app/camera_controller.rb', line 92 def tapToContinouslyAutoFocus(gestureRecognizer) return unless club.videoInput if club.videoInput.device.isFocusPointOfInterestSupported club.continuousFocusAtPoint(CGPoint.new(0.5, 0.5)) end end |
#toggleCamera(sender) ⇒ Object
100 101 102 103 104 105 106 |
# File 'app/camera_controller.rb', line 100 def toggleCamera(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 |
#toggleRecording(sender) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'app/camera_controller.rb', line 108 def toggleRecording(sender) # Start recording if there isn't a recording running. Stop recording if there is. .setEnabled(false) unless club.recorder.isRecording club.startRecording else club.stopRecording end end |
#update_button_states ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/camera_controller.rb', line 126 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 76 |
# File 'app/camera_controller.rb', line 4 def viewDidLoad super self.view.backgroundColor = UIColor.darkGrayColor self.viewFinderView = UIView.alloc.initWithFrame(UIEdgeInsetsInsetRect(self.view.bounds, [50, 20, 20, 20])) self.viewFinderView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth self.viewFinderView.backgroundColor = UIColor.lightGrayColor self.view.addSubview(self.viewFinderView) ### important ### startInView(self.viewFinderView) width = 0 height = 0 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Camera', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) height = CGRectGetHeight(.frame) .addTarget(self, action: 'toggleCamera:', forControlEvents:UIControlEventTouchUpInside) end width += 10 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Record', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) .addTarget(self, action: 'toggleRecording:', forControlEvents:UIControlEventTouchUpInside) end width += 10 self. = UIButton.(UIButtonTypeRoundedRect).tap do || .setTitle('Photo', forState:UIControlStateNormal) .sizeToFit width += CGRectGetWidth(.frame) .addTarget(self, action: 'captureStillImage:', 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:'tapToAutoFocus:') singleTap.setDelegate(self) singleTap.setNumberOfTapsRequired(1) self.viewFinderView.addGestureRecognizer(singleTap) end |
#willRotateToInterfaceOrientation(toInterfaceOrientation, duration: duration) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/camera_controller.rb', line 175 def willRotateToInterfaceOrientation(toInterfaceOrientation, duration:duration) super case toInterfaceOrientation 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 ### rotateCameraTo(new_frame, orientation:toInterfaceOrientation, duration:duration) end |