This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/cordova-plugin-media-capture.git
The following commit(s) were added to refs/heads/master by this push:
new 24a1b12 fix(ios): UI sizing of the audio capture controller according
to parent view size (#279)
24a1b12 is described below
commit 24a1b12ac62d949cd9b5ccf074715ebfd16f39b3
Author: エリス <[email protected]>
AuthorDate: Wed Aug 9 23:17:26 2023 +0900
fix(ios): UI sizing of the audio capture controller according to parent
view size (#279)
* iOS: Fixed the UI sizing for audio capture controller according to parent
view size
Co-authored-by: Denis Kovalev <[email protected]>
---
src/ios/CDVCapture.m | 153 ++++++++++++++++++++++++++-------------------------
1 file changed, 78 insertions(+), 75 deletions(-)
diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m
index aa9a0d9..f66efda 100644
--- a/src/ios/CDVCapture.m
+++ b/src/ios/CDVCapture.m
@@ -656,81 +656,6 @@
return nil;
}
-- (void)loadView
-{
- if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
- self.edgesForExtendedLayout = UIRectEdgeNone;
- }
-
- // create view and display
- CGRect viewRect = [[UIScreen mainScreen] bounds];
- UIView* tmp = [[UIView alloc] initWithFrame:viewRect];
-
- // make backgrounds
- NSString* microphoneResource = @"CDVCapture.bundle/microphone";
-
- BOOL isIphone5 = ([[UIScreen mainScreen] bounds].size.width == 568 &&
[[UIScreen mainScreen] bounds].size.height == 320) || ([[UIScreen mainScreen]
bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320);
- if (isIphone5) {
- microphoneResource = @"CDVCapture.bundle/microphone-568h";
- }
-
- NSBundle* cdvBundle = [NSBundle bundleForClass:[CDVCapture class]];
- UIImage* microphone = [UIImage imageNamed:[self
resolveImageResource:microphoneResource] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
- UIView* microphoneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
viewRect.size.width, microphone.size.height)];
- [microphoneView setBackgroundColor:[UIColor
colorWithPatternImage:microphone]];
- [microphoneView setUserInteractionEnabled:NO];
- [microphoneView setIsAccessibilityElement:NO];
- [tmp addSubview:microphoneView];
-
- // add bottom bar view
- UIImage* grayBkg = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/controls_bg"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
- UIView* controls = [[UIView alloc] initWithFrame:CGRectMake(0,
microphone.size.height, viewRect.size.width, grayBkg.size.height)];
- [controls setBackgroundColor:[UIColor colorWithPatternImage:grayBkg]];
- [controls setUserInteractionEnabled:NO];
- [controls setIsAccessibilityElement:NO];
- [tmp addSubview:controls];
-
- // make red recording background view
- UIImage* recordingBkg = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/recording_bg"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
- UIColor* background = [UIColor colorWithPatternImage:recordingBkg];
- self.recordingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
viewRect.size.width, recordingBkg.size.height)];
- [self.recordingView setBackgroundColor:background];
- [self.recordingView setHidden:YES];
- [self.recordingView setUserInteractionEnabled:NO];
- [self.recordingView setIsAccessibilityElement:NO];
- [tmp addSubview:self.recordingView];
-
- // add label
- self.timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,
viewRect.size.width, recordingBkg.size.height)];
- // timerLabel.autoresizingMask = reSizeMask;
- [self.timerLabel setBackgroundColor:[UIColor clearColor]];
- [self.timerLabel setTextColor:[UIColor whiteColor]];
- [self.timerLabel setTextAlignment:NSTextAlignmentCenter];
- [self.timerLabel setText:@"0:00"];
- [self.timerLabel
setAccessibilityHint:PluginLocalizedString(captureCommand, @"recorded time in
minutes and seconds", nil)];
- self.timerLabel.accessibilityTraits |=
UIAccessibilityTraitUpdatesFrequently;
- self.timerLabel.accessibilityTraits &= ~UIAccessibilityTraitStaticText;
- [tmp addSubview:self.timerLabel];
-
- // Add record button
-
- self.recordImage = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/record_button"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
- self.stopRecordImage = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/stop_button"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
- self.recordButton.accessibilityTraits |= [self accessibilityTraits];
- self.recordButton = [[UIButton alloc]
initWithFrame:CGRectMake((viewRect.size.width - recordImage.size.width) / 2,
(microphone.size.height + (grayBkg.size.height - recordImage.size.height) / 2),
recordImage.size.width, recordImage.size.height)];
- [self.recordButton
setAccessibilityLabel:PluginLocalizedString(captureCommand, @"toggle audio
recording", nil)];
- [self.recordButton setImage:recordImage forState:UIControlStateNormal];
- [self.recordButton addTarget:self action:@selector(processButton:)
forControlEvents:UIControlEventTouchUpInside];
- [tmp addSubview:recordButton];
-
- // make and add done button to navigation bar
- self.doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(dismissAudioView:)];
- [self.doneButton setStyle:UIBarButtonItemStyleDone];
- self.navigationItem.rightBarButtonItem = self.doneButton;
-
- [self setView:tmp];
-}
-
- (void)viewDidLoad
{
[super viewDidLoad];
@@ -785,6 +710,78 @@
}
}
+-(void) setupUI {
+ CGRect viewRect = self.view.bounds;
+ CGFloat topInset =
self.navigationController.navigationBar.frame.size.height;
+ CGFloat bottomInset = 10;
+
+ // make backgrounds
+ NSString* microphoneResource = @"CDVCapture.bundle/microphone";
+
+ BOOL isIphone5 = ([[UIScreen mainScreen] bounds].size.width == 568 &&
[[UIScreen mainScreen] bounds].size.height == 320) || ([[UIScreen mainScreen]
bounds].size.height == 568 && [[UIScreen mainScreen] bounds].size.width == 320);
+ if (isIphone5) {
+ microphoneResource = @"CDVCapture.bundle/microphone-568h";
+ }
+
+ NSBundle* cdvBundle = [NSBundle bundleForClass:[CDVCapture class]];
+ UIImage* microphone = [UIImage imageNamed:[self
resolveImageResource:microphoneResource] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
+ UIImageView* microphoneView = [[UIImageView alloc]
initWithFrame:CGRectMake(0, 0, viewRect.size.width, viewRect.size.height)];
+ [microphoneView setImage:microphone];
+ [microphoneView setContentMode:UIViewContentModeScaleAspectFill];
+ [microphoneView setUserInteractionEnabled:NO];
+ [microphoneView setIsAccessibilityElement:NO];
+ [self.view addSubview:microphoneView];
+
+ // add bottom bar view
+ UIImage* grayBkg = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/controls_bg"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
+ UIImageView* controls = [[UIImageView alloc] initWithFrame:CGRectMake(0,
viewRect.size.height - grayBkg.size.height - bottomInset,
+
viewRect.size.width, grayBkg.size.height + bottomInset)];
+ [controls setImage:grayBkg];
+ [controls setUserInteractionEnabled:NO];
+ [controls setIsAccessibilityElement:NO];
+ [self.view addSubview:controls];
+
+ // make red recording background view
+ UIImage* recordingBkg = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/recording_bg"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
+ UIColor* background = [UIColor colorWithPatternImage:recordingBkg];
+ self.recordingView = [[UIView alloc] initWithFrame:CGRectMake(0, topInset,
viewRect.size.width, recordingBkg.size.height)];
+ [self.recordingView setBackgroundColor:background];
+ [self.recordingView setHidden:YES];
+ [self.recordingView setUserInteractionEnabled:NO];
+ [self.recordingView setIsAccessibilityElement:NO];
+ [self.view addSubview:self.recordingView];
+
+ // add label
+ self.timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, topInset,
viewRect.size.width, recordingBkg.size.height)];
+ [self.timerLabel setBackgroundColor:[UIColor clearColor]];
+ [self.timerLabel setTextColor:[UIColor whiteColor]];
+ [self.timerLabel setTextAlignment:NSTextAlignmentCenter];
+ [self.timerLabel setText:@"0:00"];
+ [self.timerLabel
setAccessibilityHint:PluginLocalizedString(captureCommand, @"recorded time in
minutes and seconds", nil)];
+ self.timerLabel.accessibilityTraits |=
UIAccessibilityTraitUpdatesFrequently;
+ self.timerLabel.accessibilityTraits &= ~UIAccessibilityTraitStaticText;
+ [self.view addSubview:self.timerLabel];
+
+ // Add record button
+
+ self.recordImage = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/record_button"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
+ self.stopRecordImage = [UIImage imageNamed:[self
resolveImageResource:@"CDVCapture.bundle/stop_button"] inBundle:cdvBundle
compatibleWithTraitCollection:nil];
+ self.recordButton.accessibilityTraits |= [self accessibilityTraits];
+ self.recordButton = [[UIButton alloc]
initWithFrame:CGRectMake((viewRect.size.width - self.recordImage.size.width) /
2,
+
microphoneView.frame.size.height - bottomInset - grayBkg.size.height +
+
((grayBkg.size.height - self.recordImage.size.height) / 2),
+
self.recordImage.size.width, self.recordImage.size.height)];
+ [self.recordButton
setAccessibilityLabel:PluginLocalizedString(captureCommand, @"toggle audio
recording", nil)];
+ [self.recordButton setImage:recordImage forState:UIControlStateNormal];
+ [self.recordButton addTarget:self action:@selector(processButton:)
forControlEvents:UIControlEventTouchUpInside];
+ [self.view addSubview:recordButton];
+
+ // make and add done button to navigation bar
+ self.doneButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(dismissAudioView:)];
+ [self.doneButton setStyle:UIBarButtonItemStyleDone];
+ self.navigationItem.rightBarButtonItem = self.doneButton;
+}
+
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
UIInterfaceOrientationMask orientation =
UIInterfaceOrientationMaskPortrait;
@@ -953,4 +950,10 @@
[self dismissAudioView:nil];
}
+- (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+ [self setupUI];
+}
+
@end
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]