I've got a UIButton in my IOS app that I'm trying to remove when users have Voiceover enabled. I'm able to hide it, but it still appears in the Voiceover swipe list AND is still selectable, if I happen to click in that area of the screen. I've tried:
self.chevronButton.isHidden = true
self.chevronButton.isEnabled = false
self.chevronButton.isAccessibilityElement = false
self.chevronButton.alpha = 0
self.chevronButton.accessibilityElementsHidden = true
UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: nil)
This only seems to make the button invisible. How can I remove it from the Voiceover swipe list and make it so that is cannot be selected by touch?
Related
Hi all I am a beginner in TV OS App development.
As mentioned below image, I could move the buttons,
Button1 -> Right Arrow -> focusing Button 2
I have noticed that, When moving down next (From Button2 to Button4) focusing item frame should be with in the boundary of the Button2 and Button6.
I want to move Button1 to Button 3 when down pressed. (Button3 is not in the boundary between Button1 and Button5)
How do I fix this?
Any help will highly appreciated.
Thanks in Advance.
For this you can place a UIFocusGuide to the left of button 3. (https://developer.apple.com/documentation/uikit/uifocusguide)
The focus guide is a invisible layout guide element that will "catch" focus and redirect it to whatever view you specify.
Edit:
Full documentation with Sample
Example:
let focusGuide = UIFocusGuide()
view.addLayoutGuide(focusGuide)
focusGuide.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
focusGuide.rightAnchor.constraint(equalTo: button3.rightAnchor).isActive = true
focusGuide.topAnchor.constraint(equalTo: button3.topAnchor).isActive = true
focusGuide.bottomAnchor.constraint(equalTo: button3.bottomAnchor).isActive = true
focusGuide.preferredFocusEnvironments = [button3]
As titled, I'm using a UIButton as the titleView in the navbar. Is there a way for me to make the UIButton larger along with the navbar? When I set self.navigationController?.navigationBar.prefersLargeTitles = true, what I got is this,
I can't find any documentation on this, so I played a bit. It seems in iOS 11, you won't be able to get that title to be a button and display large at the left.
Also, I ttied playing with the frame size of the button (added below). I was unable to increase the button size, no matter what I set the frame to.
To recreate, I set up a Single View project. I embedded the view controller in a navigation controller.
In ViewController.swift's viewDidLoad, I added this code:
let titleButton = UIButton(type: .roundedRect)
titleButton.setTitle("Hello Button!", for: UIControlState.normal)
let navController = parent as! UINavigationController
navController.navigationBar.topItem!.title = "Hello???"
navController.navigationBar.topItem!.titleView = titleButton
navController.navigationBar.prefersLargeTitles = true
This ends up looking something like your example.
IF I:
set .title to empty string, or remark the line out: navbar is stretched, and no title text shows (or title text set in Interface Builder shows)
remark out .prefersLargeTitles, or set it to false: the navbar is the normal height, the button displays, but no title text displays.
remark out the titleView line, AND:
leave the .prefersLargeTitles set to true: the title text displays large at the left, and the navbar's height is stretched.
set the .prefersLargeTitles to false: the title text displays in the top center, and the navbar is normal height.
In my activity class i use both custom keyboard and android soft text keyboard. Android text soft keyboard resizes activity layout. If I open custom keyboard while soft keyboard is opened, the last one hides and layout expands back. But I open custom keyboard right after call
InputMethodManager imm = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, 0);
Here view is view with custom keyboard.
And I face the problem when custom keyboard draws twice:
When android soft keyboard is hidden, but layout is not expanded back yet. In that case custom keyboard appears at the top half of the screen.
After layout is expanded back. In that case custom keyboard appears on the bottom half of the screen.
What i want to do is somehow avoid two keyboards simultaneous appearance.
In activity code i use only SoftInput.StateAlwaysHidden WindowSoftInputMode. SoftInput.AdjustPan is not convenient because in that case some views can be hidden by android keyboard.
After hours of internet search the answer has been found. Pspdfkit has great post.
And with small investigation it has been rewritten on C# in Oncreate method:
private View decorView;
private int lastVisibleDecorViewHeight = 0;
decorView = Window.DecorView;
decorView.ViewTreeObserver.GlobalLayout += (sender, args) =>
{
Rect windowVisibleDisplayFrame = new Rect();
decorView.GetWindowVisibleDisplayFrame(windowVisibleDisplayFrame);
int visibleDecorViewHeight = windowVisibleDisplayFrame.Height();
if (lastVisibleDecorViewHeight != 0)
{
if (lastVisibleDecorViewHeight > visibleDecorViewHeight)
{
OnSoftKeyboardShown();
}
else if (lastVisibleDecorViewHeight < visibleDecorViewHeight)
{
OnSoftKeyboardHidden();
if (!isAndroidSoftKeyboardShown && customKeyboardRequested)
{
Keyboard.RequestCustomKeyboard(requestedCustomKeyboardType);
customKeyboardRequested = false;
}
}
}
lastVisibleDecorViewHeight = visibleDecorViewHeight;
};
Hope this will help someone with similar problems.
I'm working in Xcode and swift, I created a view acting as a menu that toggles on tap, when the menu comes out I can still click a test button underneath it. I don't want that to happen. I want everything behind the view to be disabled giving priority to the menu view. (View Image below)
screenshot from the sample app
Keep in mind that I'm not considering one button, if that was the case I would've disabled that specific button. This page will be a scroll view and it will be dynamic.
this is the code that I'm using:
#IBAction func MenuButton(sender: UIButton) {
if self.MenuView.frame.origin.x == -180 {
UIView.animateWithDuration(0.5, animations:{
self.MenuView.frame = CGRectMake(self.MenuView.frame.origin.x + 180, self.MenuView.frame.origin.y, self.MenuView.frame.size.width, self.MenuView.frame.size.height)
})
} else {
UIView.animateWithDuration(0.5, animations:{
self.MenuView.frame = CGRectMake(self.MenuView.frame.origin.x - 180, self.MenuView.frame.origin.y, self.MenuView.frame.size.width, self.MenuView.frame.size.height)
})
}
}
the view is hidden 180 pixels on the left side, when the menu button is clicked the view will animate 180 pixels to the right which brings it to the front. The function checks if the view is already opened so it can animate it back 180 pixel to hide it.
The only thing I need is to disable clicking through the view.
Swift 3 version that worked great for me in stopping the click through (thanks to the previous comment by #Ismail).
myAddedSubView.isUserInteractionEnabled = true
This is the 'simple, one-line' answer and works like z index (presuming you wanted the z index to be 'absolute top'.
The fact that the button is still visible and clickable means that it must be in front of the menu. If you rearrange the order of things so that the menu is in front of the button, then you should get the result that you are looking for.
I am having an odd problem with my UIView animations and a UITextfield - I need to be able to click a button, have the button animate up to reveal a textfield so the user can enter text in the text field, then when the user presses that button again user interaction is disabled on the text field and the button moves back over.
This is what I mean-
I have accomplished this to an extent by placing the textfield behind the button and disabling it at the start, then when the button is clicked the button animates up to reveal the text field, which becomes enabled:
Problem is that the button click is being triggered (or possibly just the animation) when the user goes to edit the text field. So when they go to type, the button just moves back down and covers the text field.
This is odd because I have a boolean to set whether the button moves up or down, and I do not think this is being flipped because often the button moves BELOW the textfield, which should never happen.
Here is how I'm doing this:
#IBAction func enterText(sender: UIButton) {
print("time to enter text")
if !textOpen
{
UIView.animateWithDuration(0.5, animations: {
self.textBtn.center.y -= self.textBtn.bounds.height
})
happenedTxt.userInteractionEnabled = true
}
else {
UIView.animateWithDuration(0.5, animations: {
self.textBtn.center.y += self.textBtn.bounds.height
})
happenedTxt.userInteractionEnabled = false
}
textOpen = !textOpen
}
How can I trigger the button move ONLY when the button is pressed? Why is the textfield triggering the animation? Is there some call being made to return the button to its original position?