I am using the new PDFKit framework (https://developer.apple.com/documentation/pdfkit).
I would like, like in UIScrollView, to change the contentInset of my PDFView.
Sadly, PDFView doesn't have a property scrollView or contentInset.
Thanks a lot.
PDFView doesn't have a publicly exposed UIScrollView property, but if you iterate the subviews you should find the that first subview is a PDFScrollView (UIScrollView subclass):
UIView *firstSubview = pdfView.subviews.firstObject;
if ([firstSubview isKindOfClass:[UIScrollView class]]) {
UIScrollView *pdfScrollView = (UIScrollView *)firstSubview;
pdfScrollView.contentInset = UIEdgeInsetsMake(0, 20.0f, 0, 20.0f);
}
Otherwise the only other option I can think of is to inset the view itself:
pdfView.frame = CGRectInset(pdfView.frame, 10.0f, 10.0f);
Related
I have a UIView in .xib file which I'm loading at runtime and setting it as tableHeaderView of UITableView. I have a UILabel in my xib file which can grow dynamically with fixed UIButton at bottom.
If I set the width of UILabel to fixed width it works.
If I set the Leading/Trailing on UILabel then it doesn't work :(
I'm using the below code to handle the height of headerView
-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Dynamic sizing for the header view
if (table.tableHeaderView) {
UIView *headerView = table.tableHeaderView;
float height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect headerFrame = headerView.frame;
// If we don't have this check, viewDidLayoutSubviews() will get
// repeatedly, causing the app to hang.
if (height != headerFrame.size.height) {
headerFrame.size.height = height;
headerView.frame = headerFrame;
table.tableHeaderView = headerView;
}
}
}
Anybody can explain why setting the leading/trailing is not working?
My view with constraint is like (without fixed width):
call in the end of viewDidLayoutSubviews.
[viewWithLabelAndButton setNeedLayout];
[viewWithLabelAndButton layoutIfNeeded];
I am developing app in which my parent view is UIScrollView and child views are UIView and UIButton.
When i click on UIButton i am increasing the height of UIView programatically(this works fine)
But after when i scroll my scrollView my UIView resizes to its original height, i also tried changing height of UIView in scrollViewDidScroll method but it doesn't work :(
Please help..
Here is my code snippet:
- (IBAction)ButtonClicked:(id)sender {
[UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionTransitionNone animations: ^{
MyView.frame = CGRectMake(8, 243, 304, 400);
} completion:nil];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
MyView.frame = CGRectMake(8, 243, 304, 400);
}
Thanks in advance !!
You should connect left(top, width or height) constraints as IBOutlets and should change them.
Because view is re-layouted with auto layout constraints when you scroll scrollview.
So
myViewLeftConstraint.constant = 8
myViewTopConstraint.constant = 243
myViewWidthConstraint.constant = 304
myViewHeightConstraint.constant = 400
like this.
In my iOS application i have a scrollview in which there are many imageviews and textviews.
I have to move all this views down to a fixed value, but i don't want to move them to left, right or resize them. I just want to move them down, on an event. The problem is that i can't know which are the values of these UIView.
This is my code:
for(UIView* subview in [myScrollView subviews])
{
subview.frame = CGRectMake(0, 0, screenWidth, screenHeight);
}
i'd like to do this:
for(UIView* subview in [myScrollView subviews])
{
subview.frame = CGRectMake(previousValue+100, previousValue, previousValue, previousValue);
}
I hope I explained myself
If you just want to move them down, why don't you just set scrollView's contentInset?
scrollView.contentInset = UIEdgeInsetsMake(100, previousValue, previousValue, previousValue);
this will make all your subViews down.
try something like this:
UIView *lastView;
for(UIView* subview in [myScrollView subviews])
{
CGrect lastFrame;
if (!lastView) {
lastFrame = CGRectMake(0,0,100,100); // your initial frame
} else {
lastFrame = lastView.frame;
}
lastFrame.origin.x += 100;
subview.frame = lastFrame;
lastView = subview;
}
I have a mainScrollView scrolling horizontally with photos added to it and mainScrollView's contentSize is set according to the number of photos.
To achieve the effect of scrolling to the end and swiping in a UIView with display info for user, I added the overlayScrollView to mainScrollView's subviews.
overlayScrollView contains the contentView positioned outside the frame.
CGRect frame = self.mainScrollView.frame;
frame.origin.x = CGRectGetWidth(frame) * (count-1);
UIScrollView *overlayScrollView = [[UIScrollView alloc] initWithFrame:frame];
[self.mainScrollView addSubview:overlayScrollView];
// moves contentView one frame beyond
frame.origin.x = CGRectGetWidth(frame);
UIView *contentView = [[UIView alloc] initWithFrame:frame];
contentView.backgroundColor = [UIColor redColor];
[overlayScrollView addSubview:contentView];
overlayScrollView.contentSize = CGSizeMake(overlayScrollView.frame.size.width * 2, overlayScrollView.frame.size.height);
overlayScrollView.pagingEnabled = YES;
I searched through SO on nested UIScrollViews and so subclassed UIScrollView for mainScrollView with the following method:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *child in self.subviews){
if([child isMemberOfClass:[UIScrollView class]])
if(CGRectContainsPoint(child.frame, point))
return child;
}
return self;
}
But it doesn't work. My code could be wrong. hitTest did return child (overlayScrollView) but did not scroll. Any suggestions how to code this?
My UIScrollView is not setting its contentOffset when using zoomToRect.
I have an UIScrollView with an UIImageView inside. Scrolling and zooming itself is working so far. Now I want to give the scrollview at app start a certain zoomed rect of the image view. For this I implemented zoomToRect: and it is setting the zoomsScale correctly, but it does not set the contentOffset.
Expected outcome when using zoomToRect is that the UIScrollView zooms in or out according to the selected rect and set its contentOffset according to the origin coordinates of the rect given to the zoomToRect method.
The actual behaviour is that it zooms to the correct zoomScale but my UIImageView is always at the origin 0,0 and not the expected origin of the x (475) and y (520) coordinated of the rect I specified in zoomToRect.
My images size is 1473x1473.
Here is some the code
- (void)viewDidLoad {
CGRect bounds = self.view.frame;
_imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bgImage.png"]];
self.containerView = [[UIView alloc] initWithFrame:bounds];
_containerView.contentMode = UIViewContentModeCenter;
_scrollView = [[UIScrollView alloc] initWithFrame:bounds];
_scrollView.delegate = self;
_scrollView.contentSize = _imageView.bounds.size;
_scrollView.minimumZoomScale = 0.2;
[_scrollView addSubview:_containerView];
[_containerView addSubview:_imageView];
[self.view addSubview:_scrollView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[_scrollView zoomToRect:CGRectMake(475.0, 150.0, 520.0, 747.0) animated:NO];
}
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _containerView;
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
[self printVisibleRectToConsole:scrollView];
CGSize newImageViewSizeWithScale = CGSizeMake(_imageView.bounds.size.width * _scrollView.zoomScale,
_imageView.bounds.size.height * _scrollView.zoomScale);
_scrollView.contentSize = newImageViewSizeWithScale;
}
My questions:
Why does zoomToRect does not set the contentOffset?
How can I get zoomToRect to change my contentOffset as expected?
The problem is that the view you're zooming (containerView) is not as big as the image view it contains (and which you actually want to zoom). Its frame is set to the frame of the view controller. You don't see this because a UIView doesn't clip its subviews by default.
You should initialize containerView with the bounds of your image view instead.
self.containerView = [[UIView alloc] initWithFrame:_imageView.bounds];