How to load UITreeView in collapsed form in iOS - ios

I'm using UITreeView by Varun Naharia in my iOS app. How can I load UITreeView in collapsed form first time app starts?

Hook the height constraint as IBOutlet and change it's constant to zero
-(void)viewDidLayoutSubviews
{
if(once)
{
once = NO;
self.treeViewHCon.constant = 0 ;
[self.view layoutIfNeeded ];
}
}
also set
self.treeView.clipsToBounds = YES;

Related

UITableViewCell Constraints Not Updated

I have a custom UITableViewCell with UITextView, UICollectionView and UITableView inside. They have a 10 px space between. In some cases I have only UITextView, sometimes only collection view etc.
When no text - I have to move UICollection view up by 10 px. And If I have no text, tableView and collectionView it should be zero height.
- (void)configureMiddleWrapperState
{
self.middleWrapperHasNote = self.noteTextView.text.length > 0;
self.noteTextViewTopConstraint.constant = self.middleWrapperHasNote ? 7.f : 0.f;
self.staffWrapperTopConstraint.constant = self.middleWrapperHasStaff ? 7.f : 0.f;
self.tagsWrapperTopConstraint.constant = self.middleWrapperHasTags ? 7.f : 0.f;
BOOL middleWrapperHasAtleastOne = self.middleWrapperHasNote || self.middleWrapperHasStaff ||
self.middleWrapperHasTags;
self.middleWrapperLastTenPixelSpaceConstraint.constant = middleWrapperHasAtleastOne ? 7.f : 0.f;
[self setNeedsUpdateConstraints];
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self setExcludedPaths];
[self configureMiddleWrapperState];
}
The result isn't like expected:
instead of one line.
When only text is looks like expected.
Constraints become work only if I scroll up and down many times.
try add
[self setNeedsLayout];
after
[self setNeedsUpdateConstraints];
I've found the issue. Coz my self.middleWrapperHasTags doesn't set correctly when reuse.

UIView subview autolayout issue

I have UITableView Cell in which 4 UIViews are arranged in a vertical order like this,
In each UIView, I have two Labels like this,
I have taken a IBOutlet for Height Constraint of all of the Four UIViews and I want to make the height 0 of the view when data is not available in that view. The problem is View is not getting 0 height due to the 10 px bottom constraint of UILabel inside that View.
What i am getting is like this,
Code where constraints are handled
NSString *toName = [self jointNameFromArray:evidence.arrTo];
if ([Utility isEmptyString:toName]) {
cell.toViewHeight.constant = 0;
}
else {
cell.lblToName.text = toName;
}
NSString *fromName = [self jointNameFromArray:evidence.arrFrom];
if ([Utility isEmptyString:fromName]) {
cell.fromViewHeight.constant = 0;
}
else {
cell.lblFromName.text = fromName;
}
NSString *ccName = [self jointNameFromArray:evidence.arrCc];
if ([Utility isEmptyString:ccName]) {
cell.ccViewHeight.constant = 0;
}
else {
cell.lblCCName.text = ccName;
}
NSString *custName = [self jointNameFromArray:evidence.arrCustodian];
if ([Utility isEmptyString:custName]) {
cell.custViewHeight.constant = 0;
}
else {
cell.lblCustName.text = custName;
}
[cell layoutIfNeeded];
If you're targeting iOS 9+, I'd suggesting using UIStackView, as it does exactly what you want just by setting the .hidden property of your view to true.
https://www.raizlabs.com/dev/2016/04/uistackview/
If you are unable to use UIStackView, you will need to set one of the vertical padding constraints to a lower priority than the height constraint. You will also need to set .clipsToBounds to true.
Set constraint programatically and write logic as u want it is good idea and dont forgot to set layoutifnedded.

UIWebView black color at bottom increases with Animation?

There are some posts, where UIWebView bottom is black and can be resolved by two simple ways.
1. Clear Background of UIWebView
2. Set Opaque to NO.
However, this only solves problem for static UIWebView which is not changing its Frame or Constraints.
In my case, I have a UIWebView, It is very simple Drag and Drop on Storyboard's ViewController's View. No Inheritance. I set Background clear and set opaque to NO.
It looks fine up to now. But when I apply animation, using Facebook POP library
1. SetOpaque = YES, With Animation is clips the UIWebView's content showing black color.
2. SetOpaque = NO, With Animation is clips the UIWebView's content showing nothing (a View or something comes in front)
-(void) setConstraint {
_topConstraintValue = self.topConstraint.constant - 200;
NSLog(#"Value is UP %f " ,_topConstraintValue);
}
- (IBAction)animateUp:(UIButton *)sender {
[self setConstraint];
[VSAnimation popChangeConstraintForBasicAnimation:self.topConstraint begin:0.5 newConstant:_topConstraintValue withDuartion:0.5 isEaseInAnimation:NO withCompletionBlock:nil];
}
-(void) setConstraintDown {
_topConstraintValue = 0;
_topConstraintValue = self.topConstraint.constant;
NSLog(#"Value is Down %f " ,_topConstraintValue);
}
- (IBAction)animateDown:(UIButton *)sender {
[self setConstraintDown];
[VSAnimation popChangeConstraintForBasicAnimation:self.topConstraint begin:0.5 newConstant:[self getAnimatableConstraint:_topConstraintValue] withDuartion:0.5 isEaseInAnimation:NO withCompletionBlock:nil];
}
-(float)getAnimatableConstraint:(float)constant{
return constant+200.0;
}
-(float)getReverseAnimatableConstraint:(float)constant{
return constant-200.0;
}
Where, method inside VS is as below
//VSAnimation.m
+(void)popChangeConstraintForBasicAnimation:(NSLayoutConstraint *) layoutConstraintToPopChange begin:(float) beginTime newConstant:(CGFloat) newConstant withDuartion:(float)duration isEaseInAnimation:(BOOL)isEaseIn withCompletionBlock:(void (^)(POPAnimation *anim, BOOL finished)) completitionBlock{
NSString *key = [NSString stringWithFormat:#"constraints_changed_%#", layoutConstraintToPopChange];
POPBasicAnimation *basicAnim = [layoutConstraintToPopChange pop_animationForKey:key];
if(basicAnim){
basicAnim.toValue = #(newConstant);
basicAnim.completionBlock = completitionBlock;
}else{
basicAnim = [POPBasicAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
if(isEaseIn)
basicAnim.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
else
basicAnim.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
basicAnim.toValue = #(newConstant);
basicAnim.completionBlock = completitionBlock;
basicAnim.beginTime = [self timeWithDelay:beginTime];
basicAnim.delegate = self;
basicAnim.duration = duration;
[layoutConstraintToPopChange pop_addAnimation:basicAnim forKey:key];
}
}
What is this black line/transparent line at bottom.
How to stop this from increasing when one animates UIWebView.
IMAGES:
SHOWING ANIMATION UP & ANIMATION DOWN.
#VS, After reading you source code, I saw the constraint of the 2nd webview seems to be set wrongly. After I removed the height constraint WV2.height = 0.095 * height, the problem disappeared. You have to set the WV2's height constraint properly.

How do I change the size of a UIView (UITextView) in iOS 7 based on user actions

I have an iPhone application (Six Things) that I wrote in iOS 6 which has a screen where the user enters text into a UITextView. When the keyboard is shown, the size of the UITextView was automatically shortened so that as the user was typing, the cursor was not hidden behind the keyboard (see picture).
I used the following handlers to do this:
When the keyboard was shown:
- (void)keyboardDidShow:(id)sender
{
NSDictionary* info = [sender userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
_txtSizeBase = self._txtInfo.frame;
float offset = kbSize.height < kbSize.width?kbSize.height:kbSize.width;
_txtSizeKeyboard = CGRectMake(_txtSizeBase.origin.x, _txtSizeBase.origin.y, _txtSizeBase.size.width, _txtSizeBase.size.height-offset+60);
self._txtInfo.frame = _txtSizeKeyboard;
...
}
When the "Done" button was pressed and the keyboard dismissed:
- (void)keyboardDidHide:(id)sender
{
self._txtInfo.frame = _txtSizeBase;
...
}
This worked well in iOS 6. But in iOS 7, I don't know of a way to force the view to change its size AFTER the viewDidLoad has already been called. Changing the size of the frame does not cause it to resize.
I've turned off auto-layout on this form so that I can have the screen adjust elements properly (y position) for both iOS 6/7 (using deltas in interface builder).
Any helpful suggestions would be appreciated.
---------------------- EDIT WITH SOLUTION -----------------------------
Because the solution to this was a bit tricky, I thought it would be helpful to post it.
I added a second .xib file for IOS6 (I only release for IOS 6+) with autolayout turned off and the positions adjusted as needed. Then I do the following:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if(![DeviceInfo isIOSAfter70])
{
self = [super initWithNibName:#"CreateRecordViewControllerIOS6" bundle:nibBundleOrNil];
}
else
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
}
}
** This is not the most elegant solution, but it works and I just want to support IOS 6 users, not move forward with IOS 6 dev, so there it is. **
I turned on Auto Layout for the form:
I set a bottom constraint on the text view and tied it to a an IBOutlet called _bottomConstraint.
I modified the handlers for the KeyboardDidShow/Hide as follows:
-(void)keyboardDidHide:(id)sender
{
...
if([DeviceInfo isIOSAfter70])
{ // IOS7+
if(_bottomConstraint != nil)
{
_bottomConstraint.constant = _bottomConstraintConstant;
[self.view layoutIfNeeded];
}
}
...
}
-(void)keyboardDidShow:(id)sender
{
...
if([DeviceInfo isIOSAfter70])
{ // IOS7+
if(_bottomConstraint != nil)
{
_bottomConstraintConstant = _bottomConstraint.constant;
_bottomConstraint.constant += kbSize.height;
[self.view layoutIfNeeded];
}
}
...
}
I had similar issues with settings frames under iOS7. I think that it is not very wise to fight auto-constrains. Just enable auto-constrains (if you can) and animate constrains.
You can create IBOutlet from constrain with Interface builder, or if you are creating constrains programatically leave reference to it. Than use code similar to this:
[self.view layoutIfNeeded];
self.constrainVertical.constant = 10;
[UIView animateWithDuration:0.3 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
//put some finalizing code here if needed
}];
I am moving just one constrain, just to show you how it can be done. Also, when using constrains, forget about setting frames directly.
Hope it helps.

iOS autolayout with resize

I have two views one is textView and below it is a scrollview, in my application the textView should toggle expand when touch it.I set the "Top Space to: Text View" for scrollView in IB.But When I expand the textView it seems not work.
here is the toggle expand code.
- (void)onTextViewClicked:(id)sender
{
CGRect targetFrame = _descTextView.frame;
if (_isTextViewExpand) {
targetFrame.size.height = _descTextViewNormalHeight;
_descTextView.frame = targetFrame;
_isTextViewExpand = NO;
[_contentScrollView setContentSize:CGSizeMake(320.f, kContentScrollViewDefaultHeight)];
}
else {
targetFrame.size.height = _descTextViewExpandHeight;
_descTextView.frame = targetFrame;
_isTextViewExpand = YES;
[_contentScrollView setContentSize:CGSizeMake(320.f, kContentScrollViewDefaultHeight + ( _descTextViewExpandHeight - _descTextViewNormalHeight ))];
}
}
You need a different approach entirely. With Auto Layout, you should never call -setFrame:. If you want the views to grow you should add a constraint or edit one of the existing constraints and then call either -setNeedsUpdateConstraints or -layoutIfNeeded.
Or just turn off Auto Layout.

Resources