Can't dismiss AVPlayerViewController in iOS16 - avplayerviewcontroller

Since iOS 16 made changes to AVPlayerViewController, the dismiss button ('x') in the top left corner simply doesn't work. The 'tap' is normal, but it feels like the UIButton target doesn't do anything. I feel like I'm missing something obvious. Is there a delegate method or setting that needs to be used for it to work? It all worked perfectly before iOS 16. Implementation below:
AVPlayerViewController *vc = [[AVPlayerViewController alloc] init];
vc.player = [AVPlayer playerWithURL:[NSURL URLWithString:videoInfo.VideoURL]];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:NO completion:nil];

Using animation. It can be fixed but I don't know why.
[self presentViewController:vc animated:YES completion:nil];

Related

iOS 11's Navigation Bar's RightBarButton greyed out when returning from a pushed ViewController

I set a LeftBarButton "Cancel" and a RightBarButton "OK" this way
_barButtonOK = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonOKAction)];
[_barButtonOK setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setRightBarButtonItems:#[_barButtonOK]];
_barButtonCancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonCancelAction)];
[_barButtonCancel setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setLeftBarButtonItems:#[_barButtonCancel]];
and they look like this
But when I push a ViewController and then pop it back, the OK button looks like being disabled (actually it is still enabled) like this
It is fine with iOS 10 but just grays out with iOS 11 and I don't know why. Any advice will be appreciated.
The problem is gone after the upgrading of iOS/Xcode at some point of time. Definitely it was an iOS defect.

UINavigationController pushes UIViewController and nothing happens

Here are the relevant lines of code:
...
if([top class] == [SitesViewController class]){
BackupsViewController *backup = [[BackupsViewController alloc] initWithStyle:UITableViewStyleGrouped andID:cg_id];
[websites pushViewController:backup animated:NO];
[websites pushViewController:details_controller animated:YES];
websites is a navigation controller, and it is not nil.
Now the first time I run it, it works fine. But if I sign out, and sign back in it doesn't work. In fact, nothing happens. It stays on the same page it is on. I have already checked to make sure nothing is nil. I also know that I am entering into this if statement and none others.
Here is the logout function:
AppDelegate * appDelegate = (GCAppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.tabBarController setSelectedIndex:0]
UINavigationController * topViewController = appDelegate.tabBarController.viewControllers[0];
[topViewController presentViewController:loginScreen animated:YES completion:nil];
[topViewController popToRootViewControllerAnimated:TRUE];
[self deteleKeysAndTokens: (NSString*)k_apiSecret withAccessToken: (NSString*)k_accessToken withAccessSecret:(NSString*) k_accessSecret withkAPIKey: (NSString*)k_apiKey];
In case it might help, the backupViewController is downloading a list of websites, and the detailsViewcontroller is getting information about the websites. In fact, after making the call:
[websites pushViewController:backup animated:NO];
[websites pushViewController:details_controller
animated:YES];
(This is from the first bit of code I posted.)
I check to see what the topViewController is:
UIViewController * topView = websites.topViewController;
The topViewController is the details_controller. So I know it is being pushed onto the stack. However, nothing is happening. I am on the same view I started on. I was thinking that maybe it was because I hadn't gotten all the data. But that doesn't explain (a) why it works the first time through and (b) why it just doesn't display a blank page.
It's hard to say what is wrong as from code it's not clear what is the hierarchy of views.
First make sure you are using the correct navigation controller:
UINavigationController * websites = viewController.navigationController;
[websites pushViewController:anotherViewController animated:NO];
Also I'm not sure why your logout function is so complicated. Where do you execute it?
Anyway, its not good to present view controller on navigation controller and then pop it to root. And also both of them are animated...
Please provide more code.

Best implementation for transitionWithView in Navigation Controller when the user tap BACK

I have 2 UIViewControllers inside a NavigationController.
The first one, A, has just an UISearchBar on top of a tableView, as the tableHeader.
The second one, B, has a view in the upper part of the screen (let's call it a custom TableHeader) and a table below this view.
I wanted to simulate the modal transitionFlipFromRight when pushing from UIViewController A to UIViewControllerB and to simulate the modal transitionFlipFromLeft when popping from UIViewController B to UIViewController A when the user tap the navigationItem.backBarButtonItem.
No problem for the push side:
UIViewController *vcB = [UIViewController alloc] init];
[self.navigationController pushViewController: vcB animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromRight
animations:nil
completion:nil];
It works as expected.
I have problems implementing the pop, the switch back from UIViewController B to UIViewController A.
I added this code in the UIViewController B:
-(void) viewWillDisappear: (BOOL) animated
{
[super viewWilDisappear: NO]
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
}
I can see the flip but I am not satisfied with the result because for a fraction of a second after the switch from B to A I can still see the B custom tableHeader, moved from left border by 10 points.
Should I manage the transition from B to A in viewWillDisappear or I am totally wrong in doing this?
If I am wrong, What is the correct way to handle the pop animation?
Thanks
Nicola
Why dont you try this in your viewWillDisappear itself and check whether this works?
UIViewController *vcA = [UIViewController alloc] init];
[[self retain] autorelease];
[self.navigationController pushViewController: vcA animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
[self.navigationController popViewControllerAnimated:NO];
This is a tested code. So it works fine. This should help you.

Pull-to-refresh in UICollectionViewController

I want to implement pull-down-to-refresh in a UICollectionViewController under iOS 6. This was easy to achieve with a UITableViewController, like so:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
The above implements a nice liquid-drop animation as part of a native widget.
As UICollectionViewController is a "more evolved" UITableViewController one would expect somewhat of a parity of features, but I can't find a reference anywhere to a built-in way to implement this.
Is there a simple way to do this that I'm overlooking?
Can UIRefreshControl be used somehow with UICollectionViewController despite the header and docs both stating that it's meant to be used with a table view?
The answers to both (1) and (2) are yes.
Simply add a UIRefreshControl instance as a subview of .collectionView and it just works.
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(startRefresh:)
forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
That's it! I wish this had been mentioned in the documentation somewhere, even though sometimes a simple experiment does the trick.
EDIT: this solution won't work if the collection is not big enough to have an active scrollbar. If you add this statement,
self.collectionView.alwaysBounceVertical = YES;
then everything works perfectly. This fix taken from another post on the same topic (referenced in a comment in the other posted answer).
I was looking for the same solution, but in Swift. Based on the above answer, I have done the following:
let refreshCtrl = UIRefreshControl()
...
refreshCtrl.addTarget(self, action: "startRefresh", forControlEvents: .ValueChanged)
collectionView?.addSubview(refreshCtrl)
Not forgetting to:
refreshCtrl.endRefreshing()
I was using Storyboard and setting self.collectionView.alwaysBounceVertical = YES; did not work. Selecting the Bounces and Bounces Vertically does the job for me.
The refreshControl property has now been added to UIScrollView as of iOS 10 so you can set the refresh control directly on collection views.
https://developer.apple.com/reference/uikit/uiscrollview/2127691-refreshcontrol
UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:#selector(refreshControlAction:) forControlEvents:UIControlEventValueChanged];
self.collectionView.refreshControl = refreshControl;
mjh's answer is correct.
I ran into the issue where if the the collectionView.contentSize was not larger then the collectionView.frame.size, you can not get the collectionView to scroll. You can not set the contentSize property either (at least I couldn't).
If it can't scroll, it won't let you do the pull to refresh.
My solution was to subclass UICollectionViewFlowLayout and overide the method:
- (CGSize)collectionViewContentSize
{
CGFloat height = [super collectionViewContentSize].height;
// Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
if (height < self.collectionView.bounds.size.height) {
height = self.collectionView.bounds.size.height + 1;
}
return CGSizeMake([super collectionViewContentSize].width, height);
}

How to set the starting orientation to landscape?

Hi I was checking the orientations changes of iOS6 and I made everything work fine except one thing. There is no way to start the app on landscape.
How can I do to start the app on landscape? I found this How to force a UIViewController to Portrait orientation in iOS 6 but that's not working, the app ALWAYS start in portrait and I needed to start it on landscape...
When I go to an other view and then go back to the "initial view" it is on landscape! But when the app starts it's on portrait...
Thank you!!
----------------------------- UPDATE -------------------------------
This is how I'm loading from the app delegate the main view:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myViewController = [[myViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
----------------------------- UPDATE 2------------------------------
I made it work, I changed the previous code for:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope this is useful for someone else!
Have you tried this?
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
or
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
This is working for me in both iOS 6 and iOS 5
I have another problem on trying to rotate the screen than I realize I was making the mistake of try to load the new screen with:
[self.navigationController presentModalViewController:controller animated:YES];
instead of:
[self.navigationController pushViewController:controller animated:YES];
the second one works but the first one wasn't doing what I expected.
This is how I made it work:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope it helps someone else!
I've been wrestling with this too - this is how I've fixed it:
In viewDidLoad:
CGRect frame = self.view.bounds;
if (frame.size.height > frame.size.width) {
//hack to force landscape
CGFloat holdHeight = frame.size.height;
frame.size.height = frame.size.width;
frame.size.width = holdHeight;
self.view.bounds = frame;
}
But I'd prefer a better way.

Resources