I have a UICollectionView and a UIButton above the collection view. My preferredFocus for the controller is the collection view, and this works fine on viewWillAppear, focusing on the first cell.
However, when I focus on the button and then return focus down to the collectionView, sometimes the entire collectionView becomes focused, and it's hard to get focus on one of the cells. Sometimes it focuses back from button to a cell, like it should.
I do have:
containerCollectionView?.remembersLastFocusedIndexPath = true already
How to prevent the entire collectionView from receiving focus?
Related
I have a UICollectionView that scrolls vertically with about 15 cells. Then directly below this UICollectionView I have a UIButton. I can successfully focus the UIButton, but only if I scroll down through all of the UICollectionViewCells. I am wondering if it is possible to transition focus from the first UICollectionViewCell down to the UIButton without having to scroll through all of the UICollectionView's items?
A diagram of the desired behavior:
If you really want that behavior then you can return the button in the following function,
override var preferredFocusEnvironments: [UIFocusEnvironment]
And then subclass the following function,
override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
and return false when the focus is about to go to second cell and before returning call setNeedsFocusUpdate() which will make system check for preferred focus element and moves the focus to the button.
Really wonder why you are after this behavior 🤔, but its doable.
Did you try with canFocusAtItem to all other collectionView cells to false.
Then directly the focus will go the UIButton.
I am hiding a UIButton underneath a UITextField. Normally, the UIButton responds just find. However, when I set it to hidden (or when I set alpha to 0), it stops working.
For context, I am including a hidden button under a UITextField because the clickable area to edit the textfield is small--I'd like the user to be able to click anywhere in the neighborhood of the uitextfield in order to make the text field become the first responder. Thus, the code for the button is:
- (IBAction)enterTextField:(id)sender {
[nameTextField becomeFirstResponder];
NSLog(#"Pressed");
}
However, this code does not get called when the button is hidden. Otherwise, it does get called.
Make it a custom button with UIButtonTypeCustom or set the background to clearColor.
I have a NSPanel in my MainMenu.xib called filePanel, it has a NSView called filePanelView. When buttons are clicked, I will load a NSView from a nib and add it to the filePanel like this:
[NSApp activateIgnoringOtherApps:YES];
[filePanel setIsVisible:YES];
[filePanelView addSubview:[fileBrowseViewController browseView]];
The problem is that the controls on these subviews can never be brought into focus. For example, a NSTextfield that is set to be editable is not editable, and doesn't have a focus ring around it when clicked. I can click buttons though. But on another window, a determinate progress bar has it's progress measured in grey instead of blue. Is there something I'm doing wrong in terms of needing to manually set these views as having focus?
I have a UITableView with a custom cell. On the press of a button called Edit, I want a UIButton checkMarkBox to appear on all cells. So initially checkMarkBox is hidden, but when this IBAction method is called for Edit, I want the checkMarkBox to be unhidden. When I do this now, it only unhides the box for the last cell, not all of them. So I need a way to go through every cell in my table view and unhide the check box. I'm thinking some kind of for loop that goes through all the cells will do the trick, but I'm not sure how to get that started.
When the button is pressed, set a BOOL in an instance variable for your class. In cellForRowAtIndexPath, check that BOOL and show or hide the checkMarkBox. In the IBAction for your button, set the BOOL, and then call:
[self.tableView reloadData];
The Apple Pages and Numbers apps have popovers (for "tools" etc) that close with a lovely fade out effect when you rotate the device. I'm trying to recreate this, but my popovers always seem to close instantly, so the animation of the rotation doesn't look quite as smooth. I'm currently using:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
[toolsPopoverController dismissPopoverAnimated:YES];
}
Does anyone know the best way to achieve the same effect seen in Pages/Numbers?
Thanks!
Based on the documentation for the UIPopoverController (emphasis added):
If the user rotates the device while a popover is visible, the popover controller hides the popover and then shows it again at the end of the rotation. The popover controller attempts to position the popover appropriately for you but you may have to present it again or hide it altogether in some cases. For example, when displayed from a bar button item, the popover controller automatically adjusts the position (and potentially the size) of the popover to account for changes to the position of the bar button item. However, if you remove the bar button item during the rotation, or if you presented the popover from a target rectangle in a view, the popover controller does not attempt to reposition the popover. In those cases, you must manually hide the popover or present it again from an appropriate new position. You can do this in the didRotateFromInterfaceOrientation: method of the view controller that you used to present the popover.
It would appear that by calling [toolsPopoverController dismissPopoverAnimated:YES] in the willAnimateRotationToInterfaceOrientation: method, you are dismissing with an animation while the popover is hidden during the rotation transition.
If you call the dismissPopoverAnimated:YES method in the didRotateFromInterfaceOrientation: method instead, the default behavior with the popover in the new position should present before the dismiss animation is invoked.
If the default animation is still not what you are looking for at this point, I would create a custom animation block and manage the fadeout or re-sizing explicitly to meet your desired needs.
This worked for me by calling dismissPopoverAnimated: from willRotateToInterfaceOrientation:duration:.