Weird animation behaviour while using autolayout in .xib - ios

I've a custom tableview cell with a right aligned button having following constraints:
Trailing space from superview
Fixed width
Fixed height
Top space from superview
Now when I launch my view controller, this edit icon image fly and settle down at the correct location. How can I remove that animation.
NOTE: This problem is in visible only in certain cells. I've also tried deleting and re-adding the component as well.

Fixed the problem by updating the frame and then calling the [self layoutIfNeeded];
Nothing will work if you miss [self layoutIfNeeded]; function call after updating your frames.

While working with autolayout, you should always call [self layoutIfNeeded]; after updating the frame.

Related

The UIScrollview always bounces back to top in IOS Objective C

I have a scrollview which always bounces to top after I scroll to bottom. I have tried numerous ways to fix this. I know there has been asked same kind of question but none of that helped me.
These are the code I have used
[self.nfaSscrollview setContentOffset:CGPointMake(0,3185)];
also
[self.NFASscrollview setContentSize:CGSizeMake(self.NFASscrollview.frame.size.width,3185)];
This I have written in viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
[self.NFASscrollview setContentSize:CGSizeMake(self.NFASscrollview.frame.size.width,3185)];
_NFASscrollview.scrollEnabled=YES;
_View3.hidden=YES;
self.view1HeightConstraint.constant = 0.0;
[self.view layoutIfNeeded];
3185 is just the (height+origin of Y) of the last content inside my Scroll view.
Screenshot of constraints of view
I think there might some problem with my constraints. I have no clue how to fix this.
Check for negative value in constraints of your super view and scrollview and set it as 0. Even I faced the same issue I fixed it by setting the bottom space to constraint of my Super View to 0.
Before you get the frame of NFASscrollview, try using [self.view layoutIfNeeded]. Because this allows you to get the current accurate frame of NFASscrollview from the constraints of Autolayout.

UIView position does not respect NSLayoutConstraint when altered from viewDidLoad

I have two views, one visible (grey) and one hidden (red). The visible view is constraint to the superview top with a constant of 32, and the other constraint to the superview top with a constant of 16.
The top of the visible view is also constrained to the bottom of the hidden view, with a constant of 8. This constraint has a priority of 749, because it is initially unsatisfiable.
The idea is that the visible (grey) view should be 32 points below the superview normally, but when the hidden (red) view is made visible, the original (grey) view should be 8 points below the other view (red).
I'm achieving this by keeping a strong reference to the 32-point constraint, and making it active/inactive as I'm hiding/unhiding the view (red).
Here's a picture of my layout:
This works very well normally, but I've been trying to set constraint.active = NO and redView.hidden = NO in viewDidLoad, as I need the textfield to display an error if a certain condition has not been met. For some reason, this does not work. The red view is displayed as expected, but the second view (grey) does not move down as it should (it does not respect the 749 constraint, even if the main constraint is no longer active). Here's a picture of the result:
However, I made the code to inactivate the constraint and display the view run after a small delay (using dispatch_after();), and then it suddenly works as expected:
My question is: why doesn't the view respect the constraint and move down when it is run immediately from viewDidLoad? Why does it suddenly work after a small delay? Is this a decent solution of achieving my goal, given I can get it to work properly?
call it in viewDidLayoutSubviews methode not in viewdidload.
autolayout it take some time to load so call it in viewDidLayoutSubviews.
While using autolayout - (void)viewDidLoad will return the frame which you gave in storyboard.
You have to use - (void)viewDidLayoutSubviews to update the frame according to constraints.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
//Replace self.view by your view whose constraints need to update
[self.view layoutIfNeeded];
}

How to scroll to bottom of UITableView to see all cell contents without adjusting cell height?

I am having an issue with my UITableView not being able to scroll past the last cell. It just "bounces" back up. Depending on what iPhone simulation I run, it will bounce back up past 2 cells, so if I run it on a 3.5 inch simulator, the last 2 cells are not reachable.
I have constraints setup with AutoLayout enabled, which is a requirement for me. I have looked at some suggestions on SO, trying some solutions, but so far, it does not work.
I prefer not to set the cell height, if possible.
In the scrolled state when I scroll up, I can see 2 more cells, but once I release the mouse hold, it bounces back up to the normal state with the 2 last cells not in view.
How do I allow the UITableView to be scrolled in a small window frame without adjusting the height, and still be able to see all cell contents?
Several problems:
The constraints you had set up were showing warnings. According to you app, you need to fix it by your self;
The bottom cell wasn't visible that is because of the constraints' issue.
In you swipeUpMethod method, you need to adjust your constraints. In this case, I set self.markerViewTopVerticalConstraint.constant to -(self.view.frame.size.height/2.5) - 60. So you need to calculate the constraint height according to the number of cells which will display in your tableView.
- (void)swipeUpMethod
{
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.3
animations:^{
self.markerViewTopVerticalConstraint.constant = -(self.view.frame.size.height/2.5) - 60;
[self.view layoutIfNeeded];
}];
self.swipeMarkerImageView.image = [UIImage imageNamed:#"down_arrow"];
NSLog(#"self.markersView: %#",self.markersView);
NSLog(#"self.markersTableView :%#",self.markersTableView);
}
Now, it looks like:
This is an autolayout problem. Make sure that the autolayout is set correctly. As far as I can understand from seeing your snapshot, the map view's height is constant and the table view's height is changing as per device height. Now to correctly set the autolayout, select the map view and add the following constraints, top, left, Width and height. Make sure to uncheck the "Constrain to margins". Now for the table view use the following auto layout. Add top, bottom left and right constraints.
After this, please check in other simulators. Hoppe this helps.

Adding Scroll view using storyboard in ios

I am trying to add a scroll view using storyboards in iOS. I have done so and it is working, but the problem is when I am using a scroll view of content size more than 800 it is not working. I have gone through many tutorials and have found that it will work only when autolayout is unchecked. Can we make it work with autolayout selected? Can anyone help me with this? Thanks in advance.
In order to make a scrollview scrollable, the content size must be larger than the scrollview's frame so the scrollview has something to scroll to. Use setContentSize to adjust the content size:
[scrollview setContentSize:CGSizeMake(width, height)];
refer this link UIScrollView not scrolling in iOS7 with autolayout on
try this
add the method
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[yourScrollView setContentSize:CGSizeMake(SOME_FLOAT_VALUE, SOME_OTHER_FLOAT_VALUE)];
}
I continue to have difficulties with this also. This is what I have tried. It works well, but I do get a warning, maybe someone can comment and help us all out.
Keeping auto layout on I have done the following..
In my view controller I dropped in a scrollview and sized it to whatever size was needed, but either the size of the screen or smaller. I then set the following constraints with the pin and alignment tabs for the scrollview... Top to view, bottom to view, both sides to view, and center in container. This allows for rotation.
Then, I dropped in a view and sized it to be larger than the scrollview. I have extended both the length of the view and its width for different apps. Inside this view you put all of your subviews, (image views, buttons, whatever you need) to be contained in the scrollview. For this view I have also set the following constraints... Top to scroll, bottom to scroll, width, and center in container. Then in the left screen for the storyboard I selected the bottom constraint for the view. It should be some negative number. In the attributes inspector, I then made this bottom constraint 0.
This has worked for me in the past, I can scroll in both portrait and landscape. I have also added pinch gestures and pan gestures for the view to be able to move things around. Hope this helps.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[yourScrollView setContentSize:CGSizeMake(SOME_FLOAT_VALUE, SOME_OTHER_FLOAT_VALUE)];
}
for ipad(IOS7)
SOME_FLOAT_VALUE=0;
SOME_OTHER_FLOAT_VALUE=1200;
This is enough for scrolling a view

Animate to resize height of UIView

I'm facing very weird issue, I have UIView grandWrapper namely in which I'm adding many subviews now when i animate the height of my grandWrapper to zero, ideally height of grandWrapper should be zero and all the inner views should disappear since they were existing inside that grandWrapper View but It animates the height to zero and all the subviews are still there. Can anyone help?
P.s. Im creating subviews programmatically. Thanks in advance
Make subview's autoresizingMask property contains UIViewAutoresizingFlexibleHeight if you want the subviews resize its height according to their parent's height.
Or you can set the view's clipsToBounds property to YES.
Little bit confused from your question
1.If you want to remove your grandWrapper sub views then call below function
-(void)clearReportContent
{
if(grandWrapper!=nil)
[[grandWrapper subviews] makeObjectsPerformSelector: #selector(removeFromSuperview)];
}
2.If sub views are appearing on screen when you do the grandWrapper height to zero,
then set grandWrapper.cliptoBounds=YES; at start where you add the sub view on grandWrapper.

Resources