inserted button is not visible. Constrained Layout - android-constraintlayout

When I drag and drop button in design mode. The button is not shown. why?
it is in top left corner.

Make sure the view has constraints set.
Otherwise, it behaves this way - AS even tells you.
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime...

Related

Why Xcode Storyboard preview and emulator button texts are not compatible?

I am trying to drag and drop buttons to the storyboard. The buttons seem good in my storyboard and preview like the following;
However, when I run the simulator, the button texts seem like the following;
Why the buttons are not shown to fit in the buttons of the simulator and how can I fix this?
Note: Preview and device types are iPhone13 Pro.
The iOS 15 / Xcode 13 style buttons are highly dependent on auto-layout.
Based on your screen-shots, it doesn't look like you've given the buttons any constraints.
You do NOT need to set widths or heights, but you DO want to set at least horizontal and vertical position constraints.
So, constrain all 4 of your buttons centered horizontally, and constrain:
First button Top to view Top (safe area)
Second button Top to First button Bottom
Third button Top to Second button Bottom
Fourth button Top to Third button Bottom
Then you should see them laid-out correctly at run-time.
I think it's because of the auto layout constraints. I am not very familiar with storyboards, if you don't set width of the view component, it seems fine on the storyboard but when compiling the view it actually has default size.
Try to set some constraints for width. Maybe it would help.
The first thing you need to do is to create identical buttons with identical size and with identical font size.
As you can see in your project, the buttons have different sizes, but the text is the same size in all buttons.
To make it faster - you can create one button and make a copy with option + drag’and’drop…
Then, you can put them in a Stack View. So, it will be easier for you to work with them in the future.
Select all buttons and make a Stack View...
https://i.stack.imgur.com/QLTJP.png
https://i.stack.imgur.com/OlOia.png
After that, resize your Stack View like you want.
Then, tap on a Stack View and clear the constraints.
https://i.stack.imgur.com/1pMT8.png
Fix the dimensions like this. But, without “Constrain to mergins”.
https://i.stack.imgur.com/8HKKF
After that, make for the Stack View - horizontally and vertically position in your storyboard.
https://i.stack.imgur.com/a29wL.png
The result is…
https://i.stack.imgur.com/mvQjg.png
Hope it’s break your problem! :)

UIView animation acting weird

My view controller's view has a child view -a "login" panel of sorts, with two input text fields- placed at its center, with autolayout constraints set in Interface Builder. The view controller class also has an outlet set to reference the vertical constraint and manipulate it at run time.
On startup -viewDidLayoutSubviews()-, I cache the value of the vertical constraint in a property (constraintInitialValue), calculate a value that will hide the panel beneath the view's bounds (based on both the panel's and the view's sizes) and apply that value immediately, effectively hiding the panel before the user sees the view. I also cache this calculated "off-screen" value of the constrain in another property (constraintOffscreenValue), for later use (e.g., to "hide" the panel).
(I do all this initial setup in viewDidLayoutSubviews() because it is the first opportunity to get the actual bounds of my view controller's view.)
(For the record, the original constraint value is 0.0: center Y, no offset. And, for an iPhone 6 and the current size of my panel, the "offscreen value" is -453.0.)
In the background, I authenticate the user. If that fails, I animate the login panel back into its original position (the center of the screen).
So far, so good.
Next, when the user enters their credentials and hits the return key for the password (the last input field), I perform some local validation (e.g., strings are not empty) and "dismiss" the panel by animating it back into its off-screen position. If I do it with the following code:
UIView.animateWithDuration(NSTimeInterval(0.3),
delay:NSTimeInterval(0.0),
options:UIViewAnimationOptions.CurveEaseOut,
animations: { () -> Void in
self.panelVerticalSpaceConstraint.constant = self.constraintOffscreenValue
self.view.layoutIfNeeded()
},
completion: { (finished) -> Void in
}
)
(viewDidLayoutSubviews() gets called several times during the animation, but from the second call onwards my code just returns right away. The initial setup I mentioned above does not get executed more than once)
My panel moves slightly upwards, and then the same ammount downwards, ending at the center of the screen (instead, it should disappear at the very bottom).
If I try changing the animation duration from 0.3 to 10.0 (to get a proper look at what's happening), instead the panel quickly "jumps" to almost above the upper margin of the view, and slowly animates back into the center. That is, if the initial jump didn't happen, I would obtain the desired result (move to the bottom of the view).
Any suggestions? Thanks in advance...
ADDENDUM: If, instead of trying to animate the panel downwards, I set the constraint to its off-screen value immediately, like this:
self.panelVerticalSpaceConstraint.constant = self.constraintOffscreenValue
self.view.layoutIfNeeded()
...it immediately disappears, only to bounce back into the center of the view right away! Where did that animation come from? Is the constraint somehow "resisting change"?
OK, I found the answer. For some weird quirk of fate, I can only find my mistakes after posting a question to SO (curse me a million times!).
It turns out another, separate animation was being executed concurrently (and thus, interfering with) my lower-the-panel-to-below-the-bottom-of-the-screen animation:
I happen to have a similar animation, to adjust the panel's postion up when the keyboard appears ("duck the keyboard" animation), and down back again when the keyboard is dismissed, but only on devices where actual overlap occurs (i.e., smaller screens), by checking the keyboard's dimensions (passed along the UIKeyboardWillShowNotification notification) against those of the main view and the panel.
I had completely forgotten about that one because I was testing on the iPhone 6 simulator, which screen size causes only minimal (almost imperceptible, but nevertheless present) keyboard overlap and hence panel adjustment animation. When I tried the code on the iPhone 6+ simulator (where the keyboard-ducking animation is skipped altogether because no overlapping occurs), the problem disappeared completely and all animations behaved as expected.
This other restore-panel-after-ducking-the-keyboard animation is no longer needed in my code, because the only way to dismiss the keyboard is when valid credentials have been entered, and autnentication begins (lowering the panel all the way down, off-screen). The panel only reappears if the entered credentials failed to be authenticated on the server side.

UITableView has blank space below, can't remove

I have a UITableView that displays some data that is read in at runtime and features a button below it that will refresh the list when clicked. All of that works fine, however there is a problem with the layout on the simulator.
When I run, there is a space at the bottom of the table that pushes the refresh button down. No matter how long the UITableView is, the UIButton will always be kept at that extended distance. If I overlay the bottom with the UIButton, it does display with slightly less padding. I am at a loss of how to fix this.
Image with example of behaviour: http://img864.imageshack.us/img864/9913/screenshot20120326at113.png
I think the problem is that in the interface builder your layout does not show at the same size, because it lacks the navigation bar at the top.
In the visual editor, choose the window hosting your table view, go to the attribute inspector, and choose Navigation bar for the Top Bar entry in the Simulated Metrics section of the inspector. The layout of your design will change. Resize your table view, move your button, rebuild the app, and run it again; this should do the trick.
It looks like it's because you're designing without the navigation bar simulated and you've set up your autoresizing masks incorrectly.
What you can do is either enable the simulated metric (attributes inspector in IB with the main view selected) for the top bar set to Navigation Bar, or you can go and fix your autoresizing masks. They are the red things in the size inspector in IB.
It is because when you designed the screen you didn't consider the navigation bar that is gonna come. Simply add a bar to the screen on the top and rearrange the table and button with proper autoresizing masks. It will fit.

iPhone4 how to add/animate a UIView to appear under a UIButton?

I have a "side panel" like widget in my app that can be swiped in from the side of the screen. In order to help the users find the panel, I also added a UIButton to do the same thing - scroll the panel on and off screen.
The view comes from a different view controller, otherwise I would've simply created an extra panel in the interface builder and positioned it properly.
My problem is that the side panel gets positioned over the button, so if it is displayed with a button, it can only be dismissed with a gesture.
is it possible to specify at which "depth" I add a UIView when I programmatically add it in code?
This is the snipped that slides the panel in or out within the animation block.
self.audioSystemController.view.frame =CGRectMake(0,20, 120,460);
I need the UIView to be shown below a UIButton, so the button may be used to dismiss the view. I know this is redundant, but I cannot depend on the users to simply discover the side swiping gestures :/
Thank you for your help!
Check out the insertSubview:belowSubview: method of UIView.

Scrolling through UIScrollView in Interface Builder for Xcode 4

This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilà! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.