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]
Related
I want to achieve that look of my button as shown? The right side of button which contains arrow (>) needs to be a simple label with that text. How can i do that? Is there anyway? I have checked many possibilities like taking a UIView and then adding button and labels inside it. I wanna know is that the only solution or there exist any other good one. Thanks.
Do you use Masonry or SnapKit ? Try this:
let label = UILabel()
label.text = ">"
button.addSubview(label)
label.snp.makeConstraints {
$0.right.equalToSuperview()
$0.centerY.equalToSuperview()
}
I am using a button as a title view for my UITableViewController which opens a dropdown list of categories. Selecting a category filters content of the table view by the selected category.
The button shows the name of the selected category plus a small arrow, similar to how iBooks used to look (or maybe still looks? I haven't used it in a while). I would therefore like it to have the same behaviour as a standard title and have it be large at first and collapse when the table view is scrolled.
Is there a way to do this?
Thanks
It seems because of the new large titles, IOS11 requires the constraints on the custom view in the navigationItem.titleView to be set.
Do this for example:
customView.widthAnchor.constraint(equalToConstant: 200).isActive = true
customView.heightAnchor.constraint(equalToConstant: 44).isActive = true
self.navigationItem.titleView = customView
Note this must be done for both width and height.
It should work. No need to add a button, at least in my case...
This was suggested by Apple to ensure that you don't have zero-size custom views. See slide 33 in https://developer.apple.com/videos/play/wwdc2017/204/
Looks like touches are broken for navigationItem.titleView. Gestures, tap events and buttons - nothing works
Seems like a bug in iOS 11: https://forums.developer.apple.com/thread/82466
I provisionally implemented this workaround:
private lazy var navBarActionButtonIOS11: UIButton = {
button.addTarget(self.navTitleView, action: #selector(self.navTitleView.didTapView), for: .touchUpInside)
return button
}()
[...]
navigationItem.titleView = navTitleView
if #available(iOS 11.0, *), let navBar = navigationController?.navigationBar {
navBarActionButtonIOS11.removeFromSuperview()
navBar.addSubview(navBarActionButtonIOS11)
navBarActionButtonIOS11.center.x = navBar.center.x
}
Another solution could be to just assign a UIButton to navigationItem.titleView directly.
I hope Apple fixes this soon!
Well, I had same problem. I have UIButtons in UINavigationItem.titleView and those were not reacting to touches at all. Problem is that the view where those buttons are where of size (0,0) because of auto layout. So to fix this problem you need to add additional view into your custom view, lets call it "contentView" and put all your controls inside that contentView. Also, contentView must have defined size with constraints. Quick test is to add width and height constraint to contentView. And all works again.
Hope that this helps someone.
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'm creating a basic sketching app using swift 1.2 and Xcode 6.4. The feature I'm working on is adding text to the image for future manipulation.
So far I have the text the user enters adding to the drawing via label, but it is being placed (I assume) behind the UIImage that is to be drawn upon. This is preventing the associated tap gesture from being recognised. The label is also obscured when drawn over.
How do I place the label on top of everything else to prevent it being drawn over? The end goal is to allow the user to move the label.
If I was using my usual web stack I'd set the z-index of the element to a high value via CSS.
Edit: Using view.bringSubviewToFront(label) prevents the text from being drawn over, but does not allow the tap gesture to be picked up.
Heres my code:
func printText(){
println(textString)
var label = UILabel(frame: CGRectMake(5, 100, 200, 50 ))
label.textAlignment = NSTextAlignment.Center
label.text = textString;
let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap"))
label.addGestureRecognizer(tap)
self.view.addSubview(label);
}
func handleTap() {
print("tap working")
}
Any help much appreciated.
If you want z-index use:
label.layer.zPosition = 1;
Also you could play with bringToFront method on the parent view:
self.view.bringSubviewToFront(label);
You can check that function here :
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/
Also, you should add the following:
label.userInteractionEnabled = true
to enable touches.
Try using those in the parent view:
view.bringSubviewToFront(label)
view.sendSubviewToBack(imageView)
It all depends on what you can, or want to do.
You can call label to front by
self.view.bringSubviewToFront(label)
or
You can send image view to the back by
self.view.sendSubviewToBack(imageView)
Creating an iOS app in which press a button open a window by sliding it to the right. However, if I go from portrait mode to landscape or vice-versa; and then I if I press the button, the window slides in from top left for the first time instead of sliding form the left.
How can I fix this ?
Code :
var win = Ti.UI.createWindow({left:0});
var slideLeft = Titanium.UI.createAnimation();
slideLeft.left = 0;
slideLeft.duration = 200;
var slide_it_right = Titanium.UI.createAnimation();
slide_it_right.left = -320;
slide_it_right.duration = 300;
button.addEventListener('click',function(){
win.open(slideLeft);
});
win.addEventListener('swipe',function(){
win.close(slideRight);
});
Please refer following links
Titanium: how to transition Slide left/right or up/down between 2 windows
Titanium: Slide window left/right.
I hope you'll get something valuable from here