I have a UIScrollView with subview like UILable and webviews. So when I click on a button all the content of the scrollveiw should generate as a image. I tried to generate it but it is not getting all the content of UIScrollView it is just showing only visible view.
and my code is
[Scroll.layer renderInContext:UIGraphicsGetCurrentContext()];
It is because your scrollView's contentSize is larger but its scrollView.frame is still smaller.
Instead of scrollview, add your content first into a UIView (Let say it containerView). containerView should have height-width stretchable according to your content.
After that add your containerView to scrollView. So your scrollView require contentSize = containerView.frame.size
Now try to taking screenshot for the IBOutlet of containerView, not the scrollView.
I have not tried this out, but I guess it should work in this case.
Related
In storyboard I have a UITableViewController-->UITableView-->UITableViewSecion--> with static cells
in the same UITableView I also have a UIView that holds a background image and UITextView.
A click on a button shows the UIView and set it's frame, which appears OK, but as soon as I click on the UITextView or make it firstResponder programmatically the keyboard appears and the view disappears
the code when clicking the button
self.myView.frame = CGRectMake(0, self.tableView.contentOffset.y+100, self.tableView.frame.size.width, self.tableView.frame.size.height-100);
self.myView.hidden = NO;
how can I fix this?
Can you copy paste us the code where you add the view to the tableview? Are you doing it with constraints or with frames?
The issue you are having is probably due to the fact the UITableViewControllers automatically shrink the contentSize of the UITableView they hold when the keyboard shows. If you add a UIView to your tableView with addSubview: programmatically, you might need to add a flexible bottom resize mask to make sure when the contentSize shrinks in height, your view stays attached to the top and not the bottom.
Try this on viewDidLoad:
[theViewYouAddedToTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];
I have a NSView wrapped in a NSScrollView using the IB. In the initialization function of the view (class is NoteView) containing the NSScrollView, I attempt to add subviews to the NSView as follows:
// Initialize custom view with width 802 and height 130, call it initialSubview
// Set initialSubview's frame origin to (20.0, 580.0). documentView of scrollView
// is size (842.0, 740.0)
// Let innerView be the documentView of the scrollView (I have an IBOutlet attaching
// the scrollView's document view to innerView)
[innerView addSubview:initialSubview];
When I do this, nothing shows up. Likewise, trying this:
[[[scrollView] documentView] addSubview:initialSubview];
doesn't work either. However, if I added it to the contentView:
[[[scrollView] contentView] addSubview:initialSubview];
The subview shows up fine. Any ideas?
As an addendum, if I add something like an NSButton to the documentView in the IB, nothing
shows up as well.
I figured out the issue. It seems NSScrollView and Auto-layout fight themselves.
The solution is to remove whatever you're documentView is (in my case innerView)
from their superview, setTranslatesAutoresizingMaskToConstraints to no, and re-add the view.
The code looks something like this:
[innerView removeFromSuperView];
[innerView setTranslatesAutoresizingMaskIntoConstraints:NO];
[scrollView setDocumentView:innerView];
Then you have to set any constraints you'd like manually
I am pretty sure contentView is the correct place to add it. You may also need to update the content size.
Adding views to a NSScrollView from IB adds the view to the NSScrollView's contentView(NSClipView).
According to your setup you have
NoteView is clip view(contentView) of the NSScrollView.
document view of the scroll view is innerview.
inner view(documentView)'s subview which is initialSubView is added from
-initWithFrame: of contentView.
In an NSScrollView a contentView represents the 'clipped' representation of the documentView.
Having the documentView initialized in init of the contentView is why nothing happens.
Do This
Add NoteView from -awakeFromNib or similar entry point as documentView of the NSScrollView.
Add initialSubView as a subview of NoteView.
I have a UIScrollView, with a UIImageView and UIButton inside of it.
I was reading in the answers here that if I have a single view that contains all of my zoomable content, then I should be fine. The problem is that the button doesn't zoom when the image does.
I thought that what I have would work, since the Scroll View is the zoomable view.
Do I need to create another UIView and put everything in there (and keep the same hierarchy?) ?
Have you checked your Springs and Struts? Look in the size inspector under "autosizing". Those little red lines.. if that doesn't make sense, search for 'auto layout'.
I ended up fixing this by declaring the button in code, and added a UView into the hiearchy. The uiview is a subview of the scroll view, and the imageview is a subview of the uiview. I then added the buttons to the uiview.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
...
[view addSubview:button];
I have main UIScrollView with lots off buttons which i create like this:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]
every button have an image:
UIImage *fileImage = [UIImage imageNamed:#"sun.png"];
[myButton setBackgroundImage:fileImage forState:UIControlStateNormal];
Buttons count could be more than 500. So i need to remove from UIscrollView invisible buttons with images to save memory ?
I believe in this method i need to calculate when UIscrollview is stopped scrolling and for example 20 images are invisible, then i need to remove them and reduce scroller contentOffset.
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
}
Maybe some one could give me tips on this. Or even have a good bookmarked tutorial.
I created a similar thing to this using UIViews in a UIScrollView. When the UIScrollView loads, I set the contentView size of the scrollView to be the size of all the views but only loaded the views that can be seen, then when the user scrolls i added the previous/next views and removed the hidden views.
This question helped me: How to implement UIScrollView with 1000+ subviews? especially akosma's answer
I want to make a View with three subviews stacked on top of each other with the middle subview scrollable with the others fixed.
How can I achieve this programmatically? I have tried
to set the contentsize of the root view to the size of the scrollable view but that makes all the views scroll.
-set the contentsize of the middle subview without setting any property for the root view but that makes all the views unscrollable.
Please help. I am new to iOS.
Thanks in advance
You can use the scrollViewDidScroll: delegate callback on the UIScrollView to adjust your view's position. In the callback, get the contentOffset of the scrollview and use that to set your fixed view's position.
For example, if you want your fixed view to always remain 100 px from the top of the scrollview, set its initial frame to (0, 100, width, height), and then in the callback set the frame to (0, contentOffset.y + 100, width, height).
The result is that the subview will appear fixed at a given height.
If your UIScrollView has a superview (i.e. a container view), you can add your 'fixed' view as a subview of the superview instead of the UIScrollView. You'll only have to calculate your frame coordinates once.
You can do it moving sub view from UIScrollView to super view of scrollview like:
Place/set your button over scroll view (not inside scroll view) as shown here in this snapshot. And also set button constraints (position) with respect to super view of your scrollview.
Here is ref. snapshot of hierarchy of position of each view over each-other.