Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Dùng AssetsLibrary để custom cameraview.
- 2. Giả sử focusView là 1 UIImageView dùng để show ‘focus’ lên khi người ta nhấn vào 1 điểm trên màn hình.
- // Biến này để ngăn người dùng focus lần nữa khi focus hiện tại đang animate fade out.
- // Có nhiều cách để làm, ví dụ xoá forcus view hiện tại và hiện lên location mới.
- var canFocus:Bool = true
- override func touchesBegan(
- touches: Set<NSObject>,
- withEvent event: UIEvent) {
- if (canFocus == true && isLockingTouch == false) {
- var anyTouch = touches.first as! UITouch
- var location = anyTouch.locationInView(self.view)
- var touchPercent = location.x / Config.kScreenSize.width
- if (location.y < Config.kScreenSize.height - 50) {
- canFocus = false
- focusView.center = CGPointMake(
- anyTouch.locationInView(self.view).x,
- anyTouch.locationInView(self.view).y)
- focusTo(Float(touchPercent))
- }
- }
- }
- func focusTo(value : Float) {
- focusView.alpha = 0.8;
- if let device = captureDevice {
- if(device.lockForConfiguration(nil)) {
- device.setFocusModeLockedWithLensPosition(
- value,
- completionHandler: { (CMTime) -> Void in
- UIView.animateWithDuration(
- 1.3,
- animations: { () -> Void in
- self.focusView.alpha = 0.5
- },
- completion: { (Bool) -> Void in
- self.focusView.alpha = 0
- self.canFocus = true
- })
- })
- device.unlockForConfiguration()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement