I have a UIView and it has another UIView and some UIButtons as sub view.I gave vertical constraint to my view and last UIButton.Those UIButtons are one after the other vertically designed like radio buttons and then UIView.I able to get nice design when all UIButtons and UIView are displayed one after the other.I have the issue when I need the UIView to be displayed after first UIButton and make other UIButtons hidden.No change is there in design except a big gap between UIView and first UIButton.
Thanks in advance for a solution.
We need to use the following code in order to remove constraint that has for the sub-view and last UIButton: [view_object removeConstraint:constraint_object];.After that we have to add constraint to the view and your first button.There are many ways to add constraint but as per your requirement, this is the code [view_object addConstraint:[NSLayoutConstraint constraintWithItem:sub-view_object attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:button_object attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10]];.
Related
in ios6 I had UITextfield placed on UIAlertview to take inputs from user.
but in ios7 it don't seem to be working.
Any idea how to achieve that in ios7?
Thanks,
Virat
For the same task I'm creating UIView subclasses that I add as subviews to the main window. This way they will appear on top of everything and I'm in control of the layout & functionality.
I applied gesture recognizer on particular UICollectionViewCell. It works fine. But after reloading the uicollectionview, this gesture recongizer is applied rest on collectionviewcell.
Suppose i have 10 cells. I apply gesture recongizer on 1st, 3rd, 4th,6th,7th,9th cells. Rest of cells 2nd,5th,8th cells don't have gesture recognizers. It works perfect on first time. After reload the collection view, 2nd,5th,8th cells also have gesture recognizer but i don't want. How to solve this issue. Please help me.
This is because UICollectionView reuses cells that are not visible any more. (Suppose you have 100 cells and only 8 visible - UICollectionView will keep at least 8 cells initialized, others might be reused) mwthod:
– dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:
Thus, in your method:
- (UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath
When you dequeue your cell, you should resetup gesture recognizers or remove if you don't need them
You should always attach your gesture recognizers to the collection view itself—not to a specific cell or view. The UICollectionView class is a descendant of UIScrollView, so attaching your gesture recognizers to the collection view is less likely to interfere with the other gestures that must be tracked. In addition, because the collection view has access to your data source and your layout object, you still have access to all the information you need to manipulate cells and views appropriately.
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/IncorporatingGestureSupport/IncorporatingGestureSupport.html
I have a UIViewController with a lot of UIButtons (each with a custom UIImage), and when I push that UIViewController to the UINavigationController, it does not show a smooth animation.
So basically same problem as here: Low frame rate during UINavigationController push transition
But I don't want to hide my UIButtons during the animation, I want something like what they do in this game
which is not "laggy".
How can I do that?
Thank you.
If you want to achieve the view which is similar to the one in the itunes link which you have provided then I dont see the use of lot of UIButtons. As adding too many UIButtons will make the view heavy.
Replace UIButtons with CALayer, as CALayer is light weight compare to UIButtons.
You can make use of 'name' property of CALayer to give unique name to each layer and override the hitTest method to get the layer which you tap and achieve the same functionality as UIButton.
I have a view with a lot of labels and buttons which are created on code because in IB is too complicated. This works ok.
In IB I also created an input view which I want to appear from the bottom by the tap on a button. Very much like a keyboard if you will. Because this input view is strigth forward, it has been created on IB and it contains sliders, labels, etc. I haven't added it as a subview of self.view on IB.
By the tap of the button, I set up all the constrains for the input view: I set the width, I set it on the bottom of the self.view with vertical size, then I remove this constraint, I add the actual heigth and then I animate with [self.view layoutIfNeeded].
The thing is that the input view itsef animates correctly, but its subviews not so much. They kind of appear at once.
I have tried adding a input view programmatically, with only one switch. It animates quite nicely.
I'm guessing that there is a problem with the constrains between the controls and their superView. But I'm not sure about it, because although they do not animate correctly, they are on the correct place and witht the correct proportions. I guess I'm missing something here. Maybe it's not a good idea to mix IB set controls and views and programmatically modifying them?
Does somebody have any experience with that?
Thanks in advance,
I suggest you post to Apple's dev boards on this subject. I've seen several posts there recently. The Apple Engineers who replied said that with Autolayout, you basically give autolayout ownership of your view's center, size, and sometimes, transform.
To animate views that use autolayout, you should apparently use UIView block animation and animate the constraint settings on the views. The system will then animate the changes you make.
Not sure about adding new views programmatically and having them animate into place however.
I'm currently learning iOS Programming and I have a (hopefully) simple problem:
I wrote a drawing program that works with a customized class of UIView. That gets initialised upon startup in the main view controller in the viewDidLoad method
Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];
I now want to change my program into a bit more sophisticated. I made a xib File containing some buttons, status bar and and image view. I still want to be able to draw in this new view, precisely over the image view, but not over the status bar or the buttons. But I have problems in initializing my Image_DrawDraw class it just overrides the whole xib and I'm back to my black screen where I can draw.
Thank you for your help!
When you add a subView to a view hierarchy it becomes the last item in the superview's views array property. The layering order of views is based on the views array, with the lowermost view the item at [views objectAtIndex:0] and the uppermost view the item at [views lastObject]. By arranging all of your other views on the Xib, and then adding your Image_DrawDraw view in code after the Xib has loaded, you are making it the uppermost view, so obscuring your buttons.
Instead of adding it in code, you could place it directly in the Xib.
Add a custom view to your xib. Position it above your existing xib image view, and below the buttons. Set the custom class of the view to Image_DrawDraw.
Now you won't need either of these lines of code:
Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];
To refer to you Image_DrawDraw xib view in code, you should make an IBOutlet property for it in your viewController's #interface, and connect the Xib view to the IBOutlet by CTRL-dragging a line out in the Xib file.