@@ -168,8 +168,8 @@ - (void)prepareWithCameraViewControllerType:(CameraViewControllerType)value {
168
168
}
169
169
170
170
// setting preview layer
171
- previewView = [[UIView alloc ] initWithFrame: CGRectZero ];
172
- [previewView setAutoresizingMask: UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight ];
171
+ previewView = [[UIView alloc ] initWithFrame: CGRectMake ( 0 , 0 , 1024 , 1024 ) ];
172
+ [previewView setAutoresizingMask: UIViewAutoresizingNone ];
173
173
174
174
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession: session];
175
175
}
@@ -184,36 +184,22 @@ - (id)initWithCameraViewControllerType:(CameraViewControllerType)value {
184
184
}
185
185
186
186
- (void )adjustCameraPreviewLayerOrientaion : (UIInterfaceOrientation)orientation {
187
- CATransform3D m;
188
- CGRect f = previewLayer.frame ;
189
-
190
- float offsetx = (f.size .height - f.size .width )/2 ;
191
- float offsety = (f.size .width - f.size .height )/2 ;
192
-
193
187
switch (orientation) {
194
188
case UIInterfaceOrientationLandscapeLeft:
195
- m = CATransform3DMakeTranslation (offsetx, offsety, 0 );
196
- m = CATransform3DRotate (m, M_PI/2 , 0 , 0 , 1 );
189
+ previewView.transform = CGAffineTransformMakeRotation (M_PI_2);
197
190
break ;
198
191
case UIInterfaceOrientationLandscapeRight:
199
- m = CATransform3DMakeTranslation (offsetx, offsety, 0 );
200
- m = CATransform3DRotate (m, 3 * M_PI/2 , 0 , 0 , 1 );
192
+ previewView.transform = CGAffineTransformMakeRotation (M_PI_2);
201
193
break ;
202
194
case UIInterfaceOrientationPortrait:
203
- m = CATransform3DMakeTranslation (0 , -2 , 0 );
204
- m = CATransform3DRotate (m, 0 , 0 , 0 , 1 );
195
+ previewView.transform = CGAffineTransformMakeRotation (0 );
205
196
break ;
206
197
case UIInterfaceOrientationPortraitUpsideDown:
207
- m = CATransform3DMakeTranslation (0 , -2 , 0 );
208
- m = CATransform3DRotate (m, M_PI, 0 , 0 , 1 );
198
+ previewView.transform = CGAffineTransformMakeRotation (0 );
209
199
break ;
210
200
default :
211
- m = CATransform3DMakeTranslation (0 , -2 , 0 );
212
- m = CATransform3DRotate (m, 0 , 0 , 0 , 1 );
213
201
break ;
214
202
}
215
-
216
- previewLayer.transform = m;
217
203
}
218
204
219
205
- (void )waitForSessionStopRunning {
@@ -251,7 +237,7 @@ - (id)initWithCoder:(NSCoder *)coder {
251
237
252
238
- (void )viewWillAppear : (BOOL )animated {
253
239
[super viewWillAppear: animated];
254
-
240
+
255
241
float width = self.view .frame .size .width ;
256
242
float height = self.view .frame .size .width * aspectRatio;
257
243
@@ -261,6 +247,8 @@ - (void)viewWillAppear:(BOOL)animated {
261
247
[session startRunning ];
262
248
263
249
[self adjustCameraPreviewLayerOrientaion: self .interfaceOrientation];
250
+
251
+ canRotate = YES ;
264
252
}
265
253
266
254
- (void )viewWillDisappear : (BOOL )animated {
@@ -276,9 +264,9 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
276
264
}
277
265
278
266
- (BOOL )shouldAutorotateToInterfaceOrientation : (UIInterfaceOrientation)interfaceOrientation {
279
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
280
- // for orientation test
281
- // return YES ;
267
+ // I can't understand the orienation behavior of view controllers.....
268
+ // Recommend that you don't overide this method... or please help me.
269
+ return canRotate ;
282
270
}
283
271
284
272
#pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate
0 commit comments