Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

fix camera ui a bit

roryclear5bbecc7cef2e
diff --git a/clearcam/ViewController.m b/clearcam/ViewController.m
index 5e7e7c9..ac05c04 100644
--- a/clearcam/ViewController.m
+++ b/clearcam/ViewController.m
@@ -130,27 +130,27 @@ NSMutableDictionary *classColorMap;
- (void)handleDeviceOrientationChange {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation videoOrientation;
- switch (deviceOrientation) {
- case UIDeviceOrientationLandscapeLeft:
- videoOrientation = AVCaptureVideoOrientationLandscapeRight;
- break;
- case UIDeviceOrientationLandscapeRight:
- videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
- break;
- case UIDeviceOrientationPortrait:
- videoOrientation = AVCaptureVideoOrientationPortrait;
- break;
- case UIDeviceOrientationPortraitUpsideDown:
- videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
- break;
- default:
- videoOrientation = AVCaptureVideoOrientationLandscapeRight;
- break;
+
+ // Only handle Portrait, LandscapeLeft, and LandscapeRight
+ if (deviceOrientation == UIDeviceOrientationPortrait) {
+ videoOrientation = AVCaptureVideoOrientationPortrait;
+ } else if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
+ videoOrientation = AVCaptureVideoOrientationLandscapeRight;
+ } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
+ videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
+ } else {
+ // Ignore PortraitUpsideDown and other invalid orientations (face up/down)
+ return; // No update, keep current state
}
-
+
if (self.previewLayer.connection.isVideoOrientationSupported) {
self.previewLayer.connection.videoOrientation = videoOrientation;
}
+
+ // Update UI positions
+ [UIView animateWithDuration:0.3 animations:^{
+ [self updateButtonFrames];
+ }];
}
- (void)setupCameraWithWidth:(NSString *)width height:(NSString *)height {
@@ -391,57 +391,52 @@ NSMutableDictionary *classColorMap;
self.fpsLabel.text = @"FPS: 0";
[self.view addSubview:self.fpsLabel];
- // Create the record button
+ // Rest of the setupUI code remains unchanged...
self.recordButton = [UIButton buttonWithType:UIButtonTypeCustom];
- CGFloat buttonSize = 80; // Record button size
+ CGFloat buttonSize = 80;
self.recordButton.frame = CGRectMake(0, 0, buttonSize, buttonSize);
self.recordButton.backgroundColor = [UIColor clearColor];
self.recordButton.clipsToBounds = YES;
CAShapeLayer *whiteRing = [CAShapeLayer layer];
- whiteRing.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, buttonSize - 10, buttonSize - 10)].CGPath; // 70x70
+ whiteRing.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, buttonSize - 10, buttonSize - 10)].CGPath;
whiteRing.fillColor = [UIColor clearColor].CGColor;
whiteRing.strokeColor = [UIColor whiteColor].CGColor;
whiteRing.lineWidth = 4.0;
[self.recordButton.layer addSublayer:whiteRing];
CAShapeLayer *redShape = [CAShapeLayer layer];
- redShape.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, buttonSize - 20, buttonSize - 20)].CGPath; // 60x60
+ redShape.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, buttonSize - 20, buttonSize - 20)].CGPath;
redShape.fillColor = [UIColor redColor].CGColor;
redShape.name = @"redShape";
[self.recordButton.layer addSublayer:redShape];
[self.recordButton setTitle:@"Record" forState:UIControlStateNormal];
- self.recordButton.titleLabel.alpha = 0; // Hide text
+ self.recordButton.titleLabel.alpha = 0;
[self.recordButton addTarget:self action:@selector(toggleRecording) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.recordButton];
- // Create the settings button (UNCHANGED)
self.settingsButton = [UIButton buttonWithType:UIButtonTypeSystem];
UIImage *gearIcon = [UIImage systemImageNamed:@"gear"];
[self.settingsButton setImage:gearIcon forState:UIControlStateNormal];
-
CGFloat gearButtonSize = 50;
self.settingsButton.frame = CGRectMake(0, 0, gearButtonSize, gearButtonSize);
self.settingsButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
self.settingsButton.layer.cornerRadius = gearButtonSize / 2;
self.settingsButton.clipsToBounds = YES;
self.settingsButton.tintColor = [UIColor whiteColor];
-
[self.settingsButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.settingsButton];
self.galleryButton = [UIButton buttonWithType:UIButtonTypeSystem];
UIImage *galleryIcon = [UIImage systemImageNamed:@"photo.on.rectangle"];
[self.galleryButton setImage:galleryIcon forState:UIControlStateNormal];
-
- CGFloat galleryButtonSize = 50; // Same size as settings button
+ CGFloat galleryButtonSize = 50;
self.galleryButton.frame = CGRectMake(0, 0, galleryButtonSize, galleryButtonSize);
self.galleryButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
- self.galleryButton.layer.cornerRadius = galleryButtonSize / 2; // Fixed: actual calculation, not a string
+ self.galleryButton.layer.cornerRadius = galleryButtonSize / 2;
self.galleryButton.clipsToBounds = YES;
self.galleryButton.tintColor = [UIColor whiteColor];
-
[self.galleryButton addTarget:self action:@selector(galleryButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.galleryButton];
@@ -449,39 +444,56 @@ NSMutableDictionary *classColorMap;
}
- (void)updateButtonFrames {
+ CGFloat recordButtonSize = 80;
+ CGFloat settingsButtonSize = 50;
+ CGFloat galleryButtonSize = 50;
+ CGFloat spacing = 60;
+
+ // Use safe area insets
+ UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
CGFloat screenWidth = self.view.bounds.size.width;
CGFloat screenHeight = self.view.bounds.size.height;
- CGFloat recordButtonSize = 80; // Record button size
- CGFloat settingsButtonSize = 50; // Settings button size
- CGFloat galleryButtonSize = 50; // Gallery button size (NEW)
- CGFloat margin = 20;
- CGFloat spacing = 60;
+
self.recordButton.layer.cornerRadius = recordButtonSize / 2;
self.settingsButton.layer.cornerRadius = settingsButtonSize / 2;
- self.galleryButton.layer.cornerRadius = galleryButtonSize / 2; // (NEW)
+ self.galleryButton.layer.cornerRadius = galleryButtonSize / 2;
+
+ UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
+
+ if (UIDeviceOrientationIsLandscape(orientation)) {
+ // Landscape (Left or Right)
+ CGFloat rightMargin = MAX(20, safeAreaInsets.right + 10);
+ self.recordButton.frame = CGRectMake(screenWidth - recordButtonSize - rightMargin,
+ screenHeight / 2 - recordButtonSize / 2,
+ recordButtonSize,
+ recordButtonSize);
- if (screenWidth > screenHeight) {
- // Landscape: Record button on right, settings above, gallery below, centers aligned horizontally
- self.recordButton.frame = CGRectMake(screenWidth - recordButtonSize - margin, screenHeight / 2 - recordButtonSize / 2, recordButtonSize, recordButtonSize);
- CGFloat settingsX = (screenWidth - recordButtonSize - margin) + (recordButtonSize / 2) - (settingsButtonSize / 2); // Align centers horizontally
- CGFloat settingsY = screenHeight / 2 - recordButtonSize / 2 - settingsButtonSize - spacing; // Above record button
+ CGFloat settingsX = screenWidth - recordButtonSize - rightMargin + (recordButtonSize / 2) - (settingsButtonSize / 2);
+ CGFloat settingsY = screenHeight / 2 - recordButtonSize / 2 - settingsButtonSize - spacing;
self.settingsButton.frame = CGRectMake(settingsX, settingsY, settingsButtonSize, settingsButtonSize);
- CGFloat galleryX = (screenWidth - recordButtonSize - margin) + (recordButtonSize / 2) - (galleryButtonSize / 2); // Align centers horizontally with record button
- CGFloat galleryY = screenHeight / 2 + recordButtonSize / 2 + spacing; // Below record button
+ CGFloat galleryX = screenWidth - recordButtonSize - rightMargin + (recordButtonSize / 2) - (galleryButtonSize / 2);
+ CGFloat galleryY = screenHeight / 2 + recordButtonSize / 2 + spacing;
self.galleryButton.frame = CGRectMake(galleryX, galleryY, galleryButtonSize, galleryButtonSize);
} else {
- // Portrait: Record button centered, settings to the right, gallery to the left, centers aligned vertically
+ // Portrait (only regular portrait reaches here)
+ CGFloat bottomMargin = MAX(20, safeAreaInsets.bottom + 10);
CGFloat recordX = (screenWidth - recordButtonSize) / 2;
- self.recordButton.frame = CGRectMake(recordX, screenHeight - recordButtonSize - margin, recordButtonSize, recordButtonSize);
+ self.recordButton.frame = CGRectMake(recordX,
+ screenHeight - recordButtonSize - bottomMargin,
+ recordButtonSize,
+ recordButtonSize);
+
CGFloat settingsX = recordX + recordButtonSize + spacing;
- CGFloat settingsY = (screenHeight - recordButtonSize - margin) + (recordButtonSize / 2) - (settingsButtonSize / 2); // Align centers vertically
+ CGFloat settingsY = screenHeight - bottomMargin - recordButtonSize / 2 - settingsButtonSize / 2;
self.settingsButton.frame = CGRectMake(settingsX, settingsY, settingsButtonSize, settingsButtonSize);
- CGFloat galleryX = recordX - galleryButtonSize - spacing; // Left of record button
- CGFloat galleryY = (screenHeight - recordButtonSize - margin) + (recordButtonSize / 2) - (galleryButtonSize / 2); // Align centers vertically
+ CGFloat galleryX = recordX - galleryButtonSize - spacing;
+ CGFloat galleryY = screenHeight - bottomMargin - recordButtonSize / 2 - galleryButtonSize / 2;
self.galleryButton.frame = CGRectMake(galleryX, galleryY, galleryButtonSize, galleryButtonSize);
}
+
+ // fpsLabel stays at its fixed position from setupUI (10, 30, 150, 30)
}
- (void)galleryButtonPressed {