I have few fields and UIView inside the UIScrollView (Fields on top and UIView at the bottom. UIScrollview size is larger than the screen size).
What i am thinking!
UIView should be autoresize according to its super view (UIScrollView) but it is resizing according to UIViewController view..
[UIView setAnimationBeginsFromCurrentState: YES];
this will animate all layers from the current state.
Related
My parent UIView has a frame (0,0,1024,768).
My subview with the original frame is (0,0,0,0). I add the subview to the parent view and then use PureLayout to spread the subview to fullscreen of the parent view as follow:
CGRect f1 = mySubView.frame; //- (0,0,0,0)
[myParentView addSubView:mySubView];
[mySubView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
CGRect f2 = mySubView.frame; //- (0,0,0,0)
After auto-pin edges to superview, why my subview doesn't change?
Note: I am using ObjectiveC and PureLayout
Because I need to call method "layoutIfNeeded" after adding the subview:
[myParentView addSubView:mySubView];
[mySubView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
[myParentView layoutIfNeeded];
I have two views, a designated superview and a subview.
The subview has an alpha value of 0 and has only been initialized and not been added to any superview. After the configuration of my subview I declare a UIView animation block. With this, I change the alpha of the subview to 1.0 within less than a second.
Right after I declare the animation I add the subview to my superview X.
Is it possible that the animation won't happen – and if so, why?
[UIView animateWithDuration:0.3 animations:^(void) {
[aSubview setAlpha:1.0];
}];
[aSuperview addSubview:aSubview];
I have five UIView on a UIScrollView. All of them with the same width. Each view has other subviews that resize its height according to the content assigned, thus making the parent UIView and the UIScrollView resizable as well. I am trying to keep the 5 UIView separated from each other at a certain "Padding" distance even after resizing. What I do right now is set the position of the origin.y and the height of each UIView when layoutSubviews is called. Is there an easier way to do this?
I have tried to set their position on creation like: CGRectMake(0, aboveView.frame.origin.y + aboveView.frame.size.height + Padding, width, 0) and setting its autoresizingMask to UIViewAutoresizingMaskTopMargin. Hoping that when I call sizeToFit on the main UIView, all the UView will set their positions relative to the view above them.
Overriding layoutSubviews is the right way to do this. UIKit doesn't have any built-in layout management that can do it for you.
However, you might not realize that UIScrollView sends itself layoutSubviews each time it scrolls - on every frame of the scrolling. That may be a lot more often than you need! You don't want to do a lot of work in a UIScrollView's layoutSubviews if you can avoid it.
To avoid doing extra layout, I suggest you set up your view hierarchy like this:
UIScrollView
ContainerView with layoutSubviews method
content view 1
content view 2
content view 3
content view 4
content view 5
Use a standard UIScrollView. Give it one subview, which is a custom UIView subclass (I called it ContainerView in my example). The ContainerView has your five content views as its subviews.
When you assign new content to one of your five content views, send sizeToFit to that content view. If the view's size changes, UIKit should automatically send layoutSubviews to its superview - the ContainerView. The ContainerView's layoutSubviews method adjusts the position of its subviews to maintain the padding between them, and then sets the contentSize of its parent - the UIScrollView.
- (void)layoutSubviews {
CGRect myFrame = CGRectZero;
for (UIView *subview in self.subviews) {
CGRect frame = subview.frame;
if (myFrame.size.height > 0) {
frame.origin.y = myBounds.size.height + Padding;
subview.frame = frame;
}
myFrame = CGRectUnion(myFrame, frame);
}
self.frame = myFrame;
UIScrollView *scrollView = self.superview;
scrollView.contentSize = myFrame.size;
}
This way, you don't do any extra work just because the scroll view scrolled. You only lay out your content views when the content actually changes.
I'm new to Cocoa and I'm programming a custom InspectorView.
A parent view (InspectorView) contains several subviews (InspectorCategories).
If I uncollapse a category (subview) I have to resize/relayout my parents view?
I found out that this is not possible through autoresize masks - Is this correct?
I tried it with resizeSubviewsWithOldSize in my parents view but this gets not called while resizing the subview.
How can I achieve this behavior?
There are two parts to accomplish what I think you want:
(a) In the parent view, override the sizeThatFits: method so that it computes a new size that fits around the resized subview.
(b) In the subview, override the setFrame: method and after the frame size is changed, it calls [self.superview sizeToFit] to resize the superview, perhaps like this:
-(void)setFrame:(CGRect)newFrame
{
[super setFrame:newFrame];
[self.superview sizeToFit];
}
No, it is not possible to do through autoresizing masks. Autoresizing mask defines how the view is resized when its superview changes bounds.
The subview should let its superview know what size it needs, for example through a delegate call. The superview then should resize itself and the subview.
I have a big problem concerning the resizing of a derived UIView with a UIScrollView as subview.
In the layoutSubviews message I set the frame of the UIScrollView subview. the UIScrollView contains a UIImageView with a big image which can be moved/pinched and so on. The initial contenSize of the UIScrollView is the initial image size.
So far, so good. Moving and pinching of the image works well. Now I have to change the UIView frame (in my app to maximize the UIView). im doing that in a animation block (beginAnimations/commitAnimations). So I set the new frame (which will update the width & height) an then I call [myView layoutIfNeeded] to force the UIScrollView to update its frame in the layoutSubviews message of my view.
The UIView animates correct to its new frame and if the contentOffset of the UIScrollView is currently x 0, y 0 the UIScrollView frame will be updated properly. but here's my problem: if the contentOffset of the UIScrollView is bigger than x 0, y 0 the UIScrollView will "slide in" from upper left to its final position.
I want that the UIScrollView resizes its frame properly with the parents frame and aligns the content (in my case the UIImageView) right. But how could I achieve that?
after hours of web research i found the solution for this problem:
[UIView setAnimationBeginsFromCurrentState: YES];
this will animate all layers from the current state.