Skip to content

Commit 48f29f6

Browse files
authored
Merge pull request #620 from TimOliver/xcode-18
Update new layout code for visionOS
2 parents 8ab3de3 + 79dbd74 commit 48f29f6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Objective-C/TOCropViewController/TOCropViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ - (CGRect)frameForToolbarWithVerticalLayout:(BOOL)verticalLayout
286286
CGRect frame = CGRectZero;
287287
if (!verticalLayout) { // In landscape laying out toolbar to the left
288288
if (@available(iOS 26.0, *)) {
289+
#if !TARGET_OS_VISION
289290
CGFloat minPadding = 8.0f;
291+
#else
292+
CGFloat minPadding = 16.0f;
293+
#endif
290294
frame.origin.x = insets.left + minPadding;
291295
frame.origin.y = minPadding;
292296
frame.size.width = kTOCropViewControllerToolbarHeight;
@@ -314,13 +318,17 @@ - (CGRect)frameForToolbarWithVerticalLayout:(BOOL)verticalLayout
314318
insets.bottom = 8.0f;
315319
}
316320

321+
#if !TARGET_OS_VISION
317322
const char* components[] = {"Radius", "Corner", "display", "_"};
318323
NSString *selectorName = @"";
319324
for (NSInteger i = 3; i >= 0; i--) {
320325
selectorName = [selectorName stringByAppendingString:[NSString stringWithCString:components[i]
321326
encoding:NSUTF8StringEncoding]];
322327
}
323328
const CGFloat cornerRadius = [[UIScreen.mainScreen valueForKey:selectorName] floatValue];
329+
#else
330+
const CGFloat cornerRadius = 64.0f;
331+
#endif
324332
frame.size.width = CGRectGetWidth(self.view.bounds) - MAX(cornerRadius, insets.bottom * 2.0f);
325333
} else {
326334
frame.size.width = CGRectGetWidth(self.view.bounds);

Objective-C/TOCropViewController/Views/TOCropToolbar.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ - (void)setup {
5858
self.backgroundView = [[UIView alloc] initWithFrame:self.bounds];
5959

6060
UIView *containerView = self;
61+
#ifdef __IPHONE_26_0
6162
if (@available(iOS 26.0, *)) {
63+
UIVisualEffect *effect = nil;
64+
#if !TARGET_OS_VISION
6265
UIGlassEffect *glassEffect = [UIGlassEffect effectWithStyle:UIGlassEffectStyleClear];
6366
glassEffect.interactive = YES;
64-
_glassView = [[UIVisualEffectView alloc] initWithEffect:glassEffect];
67+
effect = glassEffect;
68+
#else
69+
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleProminent];
70+
effect = blurEffect;
71+
#endif
72+
_glassView = [[UIVisualEffectView alloc] initWithEffect:effect];
6573
_glassView.cornerConfiguration = [UICornerConfiguration capsuleConfiguration];
6674
_glassView.userInteractionEnabled = YES;
6775
[self addSubview:_glassView];
@@ -72,6 +80,10 @@ - (void)setup {
7280
self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.12f alpha:1.0f];
7381
[self addSubview:self.backgroundView];
7482
}
83+
#else
84+
self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.12f alpha:1.0f];
85+
[self addSubview:self.backgroundView];
86+
#endif
7587

7688
// On iOS 9 and up, we can use the new layout features to determine whether we're in an 'Arabic' style language mode
7789
_reverseContentLayout = ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft);
@@ -103,11 +115,17 @@ - (void)setup {
103115
[_doneIconButton setImage:[TOCropToolbar doneImage] forState:UIControlStateNormal];
104116
[_doneIconButton setTintColor:[UIColor colorWithRed:1.0f green:0.8f blue:0.0f alpha:1.0f]];
105117
[_doneIconButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
118+
#if defined(__IPHONE_26_0)
106119
if (@available(iOS 26.0, *)) {
120+
#if !TARGET_OS_VISION
107121
UIButtonConfiguration *configuration = [UIButtonConfiguration prominentGlassButtonConfiguration];
108122
configuration.baseForegroundColor = [UIColor blackColor];
123+
#else
124+
UIButtonConfiguration *configuration = [UIButtonConfiguration filledButtonConfiguration];
125+
#endif
109126
_doneIconButton.configuration = configuration;
110127
}
128+
#endif
111129
[self addSubview:_doneIconButton];
112130

113131
// Set the default color for the done buttons
@@ -132,9 +150,15 @@ - (void)setup {
132150
_cancelIconButton = [UIButton buttonWithType:UIButtonTypeSystem];
133151
[_cancelIconButton setImage:[TOCropToolbar cancelImage] forState:UIControlStateNormal];
134152
[_cancelIconButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
153+
#if defined(__IPHONE_26_0)
135154
if (@available(iOS 26.0, *)) {
155+
#if !TARGET_OS_VISION
136156
_cancelIconButton.configuration = [UIButtonConfiguration clearGlassButtonConfiguration];
157+
#else
158+
_cancelIconButton.configuration = [UIButtonConfiguration filledButtonConfiguration];
159+
#endif
137160
}
161+
#endif
138162
[self addSubview:_cancelIconButton];
139163

140164
_clampButton = [UIButton buttonWithType:UIButtonTypeSystem];

0 commit comments

Comments
 (0)