UIWindow subview disappear immediately on ios 13 - objective-c

I am upgrading my app to use iOS 13. I have been using a UIWindow to add image to the current screen. However in ios 13 the image will appear, but then disappear straight away. I tried building in previous version, which is ios 12.2, and it's working fine.
this is my code:
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
UIImage *image = [UIImage imageNamed:#"test_badge" inBundle:VTBundle compatibleWithTraitCollection:nil];
UIImageView *badgeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, [currentWindow bounds].size.height-115, 115, 115)];
badgeImageView.tag =100101;
badgeImageView.image = image;
[currentWindow addSubview:badgeImageView];

Related

NSSavePanel accessory view disabled in macOS 11 Big Sur

I create a new macOS app in XCode.
I add the entitlement com.apple.security.files.user-selected.read-write with value YES (to allow usage of NSSavePanel)
In AppDelegate.m, I implement applicationDidFinishLaunching as follows:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSSavePanel* nssavepanel = [NSSavePanel savePanel];
NSButton* nsbutton = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 50, 20)];
[nsbutton setTitle:#"Button title"];
[nssavepanel setAccessoryView:[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 200, 80)]];
[[nssavepanel accessoryView] addSubview:nsbutton];
[nssavepanel beginWithCompletionHandler:^(NSModalResponse result) {}];
}
When I start the application, I see a panel with a button.
On macOS 10.15.3, I can click the button in the acceessory view.
On macOS 11.0 Beta (20A4300b), I cannot click the button -- the whole accessory view seems to be disabled. (If I use runModal or beginSheetModalForWindow instead of beginWithCompletionHandler, the accessory view works as expected.) Is this a bug? Am I doing something wrong here?

Translucent Viewcontroller over another Viewcontroller with different Orientation behaviour

For an app targeted at both iOS 7 and iOS 8, I'm using two ViewControllers which should have the following characteristics:
ViewController 1 (VC1) is in Portrait Mode
VC1 created ViewController 2 (VC2) which is in Landscape mode
VC2 has a translucent background so that VC1's contents are visible
I've referred to IOS 7: Transparent Viewcontroller Background over another Viewcontroller with different Orientation behaviour but the solution provided does not work. On iOS 8, I can either get landscape orientation or transparency for VC2 but not both
Here's what I'm doing:
self.view.backgroundColor = [UIColor clearColor];
UILabel* label = [[UILabel alloc] initWithFrame:self.view.frame];
label.text = #" I'M VC1";
[self.view addSubview:label];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
LandscapeViewController* lvc = [[LandscapeViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
//Uncomment this line for transparency but loses orientation
//lvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:lvc animated:YES completion:nil];
});
Any idea what's wrong and how can I make it work?

Position UILabel in area relative to screen resolution

I am trying to position UILabel relative to screen resolution (iPhone v iPad) so that the UILabel does not interfere with splash screen graphics at start-up. When the app was iPhone only, the label was located properly. Once the app was made universal, the Label interfered with the image on iPad (of course)
I am using the method below, which works fine, but it is not very forward thinking in terms of new devices and/or new screen resolutions.
Can anyone suggest a more efficient way to display the UILabel "Connecting to Server..." within the area circled in red on the attached image at the link below (I do not have auth to post images here yet)?
UILabel *loadingLabel;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 350, self.window.frame.size.width, 20)];
}
else
{
loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 700, self.window.frame.size.width, 20)];
}
loadingLabel.text = #" Connecting to Server...";
loadingLabel.textAlignment = UITextAlignmentCenter;
loadingLabel.textColor = [UIColor whiteColor];
loadingLabel.backgroundColor = [UIColor clearColor];
Splash Screen
You can use the autoresizingMask property to accomplish it.
set your origin.y on the label to be self.window.bounds.size.height - 200 or so. Then set the autoresizingMask to be UIViewAutoresizingMakFlexibleBottomMargin

How to show a "Loading..." gif image above the Splash image in objective c?

I want to show a GIF image over the splash-screen while the app is loading its data.
I have splash image that is showing for at least about 3 or 4 seconds which is why I want to show loading text, like a gif image, over the splash image so that users think that app is loading.
just add one label to your splash image and an NSTimer which change it's text periodically just as below
splash = [[UIImageView alloc] initWithFrame:self.window.frame];
splash.image = [UIImage imageNamed:#"splash"];
[self.window addSubview:splash];
this is the code i use to show my splash screen and then
NSTimer *loading = [[NSTimer alloc]init];
[loading performSelector:#selector(YOUR_SELECTOR) withObject:YOUR_LABEL afterDelay:0.3f];
where YOUR_SELECTOR is method in which you set the label text and YOUR_LABEL is label for which you set the text
EDIT
sorry for NSTimer actually i used activityindicator with text loading...
in application:didFinishLaunchingWithOptions: method
the code for it is
splash = [[UIImageView alloc] initWithFrame:self.window.frame];
splash.image = [UIImage imageNamed:#"splash"];
[self.window addSubview:splash];
hud = [[MBProgressHUD alloc]initWithView:splash];
[splash addSubview:hud];
hud.labelText = #"Loading...";
[hud show:YES];
[self performSelector:#selector(Load_FirstView) withObject:nil afterDelay:3];
[self.window makeKeyAndVisible];
and Load_FirstView method is as follow
-(void)Load_FirstView
{
[splash removeFromSuperview];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
masterViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
}
If you are using the Default.png as a splash image, then there is no way to animate that. One way would be to launch the app quicker, only to then show an animated view for the duration of loading the data. So basically your only solution would be to move away from Default.png and use a custom view instead that can be animated.
Start off by using the Default.png and then load a UIView that contains a single UIImageView with the same frame as the UIView (entire screen). Set the Default.png as the UIImage of the ImageView and add whatever controls (such as the UIActivityIndicatorView) as you need.

applicationMusicPlayer volume notification

I am using an applicationMusicPlayer and when i try to change the volume appear the visual notification, as shown in the picture.
Here the code I am using:
[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolune];
Anyone knows how to hide this notification?
I don't know where the docs says so, but if you add a MPVolumeView view to your app the system volume overlay goes away. Even if it is not visible:
- (void) viewDidLoad
{
[super viewDidLoad];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectZero];
[self.view addSubview: volumeView];
[volumeView release];
...
}
You can use the hardware volume buttons, the setVolume method or directly interact with the control (if visible) that the overlay doesn't show up.
For iOS6 I had to set an image with alpha 0 and non-zero size to the MPVolumeView's image fields in order to get the default volume change notification to disappear.
// hide the hardware volume slider
UIImage *thumb = [[UIImage alloc] initWithCIImage:[UIImage imageNamed:#"volumeHider"].CIImage scale:0.0 orientation:UIImageOrientationUp];
MPVolumeView *hwVolume = [[MPVolumeView alloc] initWithFrame:self.frame];
[hwVolume setUserInteractionEnabled:NO];
hwVolume.showsRouteButton = NO;
[hwVolume setVolumeThumbImage:thumb forState:UIControlStateNormal];
[hwVolume setMinimumVolumeSliderImage:thumb forState:UIControlStateNormal];
[hwVolume setMaximumVolumeSliderImage:thumb forState:UIControlStateNormal];
[self addSubview:hwVolume];
This made the MPVolumeView be "visible" on the screen, but invisible to the user.
I encountered the same issue recently. Instead of adding the MPVolumeView to current view controller's view, I add it to the application's window once at the start of the app:
CGRect rect = CGRectMake(-500, -500, 0, 0);
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:rect];
[self.window addSubview:volumeView];
This works in both iOS 7 and 8.
Swift 3
You can hide the System MPVolumeView using
override func viewDidLoad() {
super.viewDidLoad()
let volumeView = MPVolumeView(frame: CGRect.zero)
self.view.addSubview(volumeView)
}
I had success with this in iOS 6. Although it wouldn't perform well. It caused quite a bit of lag when sliding the thumbImage. I did have to take out the last 2 lines of code in order for this to work.
[volumeView release];
...
For me, on iOS 7, none of above solutions worked. Here is how I did it:
_volume = [[MPVolumeView alloc] initWithFrame: CGRectMake(-100,-100,16,16)];
_volume.showsRouteButton = NO;
_volume.userInteractionEnabled = NO;
[self.view addSubview:_volume];
[_volume release];
That is, simply set MPVolumeView's frame to an off-screen location such as (-100,-100).