How to handle the change of orientation like the standard camera application on the iPhone
up vote
1
down vote
favorite
I use AVFoundation framework to get access to camera.
In the standard camera application, when the orientation changes only the rotation of the icons on the buttons.
But when I try to do something like, I have a problem related to the orientation changes animation. Preview view is rotated and the area behind it is black and has image jerks when turning.
Now I have this code:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureManager.previewLayer.transform=CATransform3DMakeRotation(0, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI+M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
}
My idea it is use transform animation to deal with rotation animation but I get problems with glithes.
How can create camera preview view and solve problems with orientation change?
May be I must use other instrument to work with camera? Not AVFoundation framework?
I know that I can lock orientation and use accelerometer to deal with buttons icons. But the i get problems with some subviewcontrollers.
Sorry for terrible english.
iphone ios camera-overlay
add a comment |
up vote
1
down vote
favorite
I use AVFoundation framework to get access to camera.
In the standard camera application, when the orientation changes only the rotation of the icons on the buttons.
But when I try to do something like, I have a problem related to the orientation changes animation. Preview view is rotated and the area behind it is black and has image jerks when turning.
Now I have this code:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureManager.previewLayer.transform=CATransform3DMakeRotation(0, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI+M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
}
My idea it is use transform animation to deal with rotation animation but I get problems with glithes.
How can create camera preview view and solve problems with orientation change?
May be I must use other instrument to work with camera? Not AVFoundation framework?
I know that I can lock orientation and use accelerometer to deal with buttons icons. But the i get problems with some subviewcontrollers.
Sorry for terrible english.
iphone ios camera-overlay
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I use AVFoundation framework to get access to camera.
In the standard camera application, when the orientation changes only the rotation of the icons on the buttons.
But when I try to do something like, I have a problem related to the orientation changes animation. Preview view is rotated and the area behind it is black and has image jerks when turning.
Now I have this code:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureManager.previewLayer.transform=CATransform3DMakeRotation(0, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI+M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
}
My idea it is use transform animation to deal with rotation animation but I get problems with glithes.
How can create camera preview view and solve problems with orientation change?
May be I must use other instrument to work with camera? Not AVFoundation framework?
I know that I can lock orientation and use accelerometer to deal with buttons icons. But the i get problems with some subviewcontrollers.
Sorry for terrible english.
iphone ios camera-overlay
I use AVFoundation framework to get access to camera.
In the standard camera application, when the orientation changes only the rotation of the icons on the buttons.
But when I try to do something like, I have a problem related to the orientation changes animation. Preview view is rotated and the area behind it is black and has image jerks when turning.
Now I have this code:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureManager.previewLayer.transform=CATransform3DMakeRotation(0, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureManager.previewLayer.transform=CATransform3DMakeRotation(M_PI+M_PI/2, 0, 0, 1.0);
captureManager.previewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
}
My idea it is use transform animation to deal with rotation animation but I get problems with glithes.
How can create camera preview view and solve problems with orientation change?
May be I must use other instrument to work with camera? Not AVFoundation framework?
I know that I can lock orientation and use accelerometer to deal with buttons icons. But the i get problems with some subviewcontrollers.
Sorry for terrible english.
iphone ios camera-overlay
iphone ios camera-overlay
asked Jan 21 '13 at 22:13
Alexander Kopytov
378
378
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You need to disable landscape orientation for your controller and update layout of icons etc by handling orientation change notifications. In this topic it is described right - How to handle autorotation in AVCaptureVideoPreviewLayer?
add a comment |
up vote
0
down vote
Nikita's answer works but requires extra code to handle the behavior of the UI elements when the device rotates. If that's too much trouble, another option (which I implemented and works) is to have 2 different UIWindow instances, one for the camera's preview layer and one for the UI elements to display on to. Notice that for this to work, the Window with the UI elements needs to have a transparent background.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14448192%2fhow-to-handle-the-change-of-orientation-like-the-standard-camera-application-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to disable landscape orientation for your controller and update layout of icons etc by handling orientation change notifications. In this topic it is described right - How to handle autorotation in AVCaptureVideoPreviewLayer?
add a comment |
up vote
1
down vote
accepted
You need to disable landscape orientation for your controller and update layout of icons etc by handling orientation change notifications. In this topic it is described right - How to handle autorotation in AVCaptureVideoPreviewLayer?
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to disable landscape orientation for your controller and update layout of icons etc by handling orientation change notifications. In this topic it is described right - How to handle autorotation in AVCaptureVideoPreviewLayer?
You need to disable landscape orientation for your controller and update layout of icons etc by handling orientation change notifications. In this topic it is described right - How to handle autorotation in AVCaptureVideoPreviewLayer?
edited May 23 '17 at 12:27
Community♦
11
11
answered Feb 23 '13 at 22:25
Nikita Leonov
5,1412537
5,1412537
add a comment |
add a comment |
up vote
0
down vote
Nikita's answer works but requires extra code to handle the behavior of the UI elements when the device rotates. If that's too much trouble, another option (which I implemented and works) is to have 2 different UIWindow instances, one for the camera's preview layer and one for the UI elements to display on to. Notice that for this to work, the Window with the UI elements needs to have a transparent background.
add a comment |
up vote
0
down vote
Nikita's answer works but requires extra code to handle the behavior of the UI elements when the device rotates. If that's too much trouble, another option (which I implemented and works) is to have 2 different UIWindow instances, one for the camera's preview layer and one for the UI elements to display on to. Notice that for this to work, the Window with the UI elements needs to have a transparent background.
add a comment |
up vote
0
down vote
up vote
0
down vote
Nikita's answer works but requires extra code to handle the behavior of the UI elements when the device rotates. If that's too much trouble, another option (which I implemented and works) is to have 2 different UIWindow instances, one for the camera's preview layer and one for the UI elements to display on to. Notice that for this to work, the Window with the UI elements needs to have a transparent background.
Nikita's answer works but requires extra code to handle the behavior of the UI elements when the device rotates. If that's too much trouble, another option (which I implemented and works) is to have 2 different UIWindow instances, one for the camera's preview layer and one for the UI elements to display on to. Notice that for this to work, the Window with the UI elements needs to have a transparent background.
answered Nov 20 at 11:39
alasker
199415
199415
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14448192%2fhow-to-handle-the-change-of-orientation-like-the-standard-camera-application-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown