增加换肤功能

This commit is contained in:
启星
2025-08-14 10:07:49 +08:00
parent f6964c1e89
commit 4f9318d98e
8789 changed files with 978530 additions and 2 deletions

View File

@@ -0,0 +1,61 @@
// Created by Tencent on 2023/06/09.
// Copyright © 2023 Tencent. All rights reserved.
#import "TUIMotionManager.h"
#import <CoreMotion/CoreMotion.h>
@import UIKit;
@interface TUIMotionManager ()
@property(nonatomic, strong) CMMotionManager *motionManager;
@end
@implementation TUIMotionManager
- (instancetype)init {
self = [super init];
if (self) {
_motionManager = [[CMMotionManager alloc] init];
_motionManager.deviceMotionUpdateInterval = 1 / 15.0;
if (!_motionManager.deviceMotionAvailable) {
_motionManager = nil;
return self;
}
__weak __typeof(self) weakSelf = self;
[_motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMDeviceMotion *motion, NSError *error) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
[strongSelf performSelectorOnMainThread:@selector(handleDeviceMotion:) withObject:motion waitUntilDone:YES];
}];
}
return self;
}
- (void)handleDeviceMotion:(CMDeviceMotion *)deviceMotion {
double x = deviceMotion.gravity.x;
double y = deviceMotion.gravity.y;
if (fabs(y) >= fabs(x)) {
if (y >= 0) {
_deviceOrientation = UIDeviceOrientationPortraitUpsideDown;
_videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
} else {
_deviceOrientation = UIDeviceOrientationPortrait;
_videoOrientation = AVCaptureVideoOrientationPortrait;
}
} else {
if (x >= 0) {
_deviceOrientation = UIDeviceOrientationLandscapeRight;
_videoOrientation = AVCaptureVideoOrientationLandscapeRight;
} else {
_deviceOrientation = UIDeviceOrientationLandscapeLeft;
_videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
}
}
}
- (void)dealloc {
[_motionManager stopDeviceMotionUpdates];
}
@end