I used to use these two lines to zoom out on the content of my scrollview. However since iOS8, I can't zoom out anymore. It does nothing.
Can someone explain to me why. I have autolayout turned off.
[scrollView setZoomScale:0.3 animated:YES];
scrollView.contentSize = CGSizeMake(tempSize.width*0.3, tempSize.height*0.3);
I am not sure if this will help you, but this method works for me when zooming in iOS 8. In this code, an imageView is in the scroll view.
- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView.minimumZoomScale = 0.5;
self.scrollView.maximumZoomScale = 6.0;
self.scrollView.contentSize = self.PhotoView.frame.size;
self.scrollView.delegate = self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.PhotoView;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView*)view atScale:(CGFloat)scale{
}
Related
I'm trying to implement a growing UITextView with the content size, I am using this class and autolayout and it works great but my problem is that my inner scroll view is not scrolling.
It was scrolling before adding the methods for growing text view in viewDidLoad.
This is what is in my xib:
View
outerScrollView
innerScrollView
labels
Growing UITextView
I do this to switch scrolling between scrollview
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if([scrollView isEqual:self.innerScrollview]){
self.outerScrollview.scrollEnabled = NO;
self.innerScrollview.scrollEnabled = YES;
}
else{
self.outerScrollview.scrollEnabled = YES;
self.innerScrollview.scrollEnabled = NO;
}
}
and in viewDidLoad where the "msg" is the growing textview:
self.msgHandler = [[GrowingTextViewHandler alloc]initWithTextView:self.msg withHeightConstraint:self.msgHeight];
[self.msgHandler updateMinimumNumberOfLines:1 andMaximumNumberOfLine:INT_MAX];
and in textViewDidChange
- (void)textViewDidChange:(UITextView *)textView {
[self.msgHandler resizeTextViewWithAnimation:YES];
}
so why is the growing text affecting the scrolling of the inner scrollview?
int outerContentHeight = self.outer_last_label.frame.size.height + self.outer_last_label.frame.origin.y;
int innerContentHeight = self.inner_last_label.frame.size.height + self.inner_last_label.frame.origin.y;
[self.outerSrollview setContentSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width,outerContentHeight)];
[self.innerScrollview setContentSize:CGSizeMake(self.scrollview2.frame.size.width, innerContentHeight)];
I have managed to fix it but I removed the use of the class"GrowingTextViewHandler" and I did this instead
I changed "scrollViewDidScroll" to this:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if([scrollView isEqual:self.innerScrollview]){
[self.view insertSubview:self.innerScrollview atIndex:0];
}
else{
[self.view insertSubview:self.outerScrollview atIndex:0];
}
}
and changed "textViewDidChange" to this
- (void)textViewDidChange:(UITextView *)textView {
float height = self.msg.contentSize.height;
[UITextView beginAnimations:nil context:nil];
[UITextView setAnimationDuration:0.5];
self.msgHeightConstraint.constant = height + 10.0; //Give it some padding
[UITextView commitAnimations];
}
Please set the content size of the scroll view, Do not change anything in the code, and check,
[self.scrollViewOuter setContentSize:CGSizeMake(200, 1000)];
[self.scrollViewInner setContentSize:CGSizeMake(200, 1000)];
My both the scroll views are working if, I add content size in it.
It is a bit tricky to explain, but I will try. When I navigate backwards from the "Mercurial page" (see picture) when the scrollview is scrolled, my app crashes. But when it is not scrolled, the app does not crash... I have implemented <UIScrollViewDelegate> Any help would be greatly appreciated! Here are some pictures and some code that I have in my app:
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self.scrollView layoutIfNeeded];
self.scrollView.contentSize=self.contentView.bounds.size;
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat yPos = -scrollView.contentOffset.y;
if (yPos > 0) {
CGRect imgRect = self.imageView.frame;
imgRect.origin.y = scrollView.contentOffset.y;
imgRect.size.height = HeaderHeight+yPos;
self.imageView.frame = imgRect;
}
this worked for me.
-(void)viewWillDisappear:(BOOL)animated{
[self.scrollView setDelegate:nil];
}
I have searched for a while now, and can't find anything that is specific to my problem.
Basically, I have an image of a large map, I want users to be able to zoom in and out, and scroll through the map. I literally have all aspects of the zooming and scrolling working, although when I start up the app, the image (within the scroll view) is massive! The image is a large file (1200x1024) but it has to be so users can zoom right in without any pixelation.
My question is, how can I make it so when I start the app, that image (map) fits to the size of the screen, and then from there, users can zoom in and scroll and etc? Because right now is looks like this when I start up: http://i.stack.imgur.com/kq1en.png
Thank you heaps!
Current Code: (Under the 'FireViewController.m' file)
#synthesize scrollView, imageView;
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ returnimageView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Mezzanine Level"]];
self.imageView = tempImageView;
scrollView.maximumZoomScale = 3.0;
scrollView.minimumZoomScale = 0.3;
scrollView.clipsToBounds = YES;
scrollView.delegate = self;
[scrollView addSubview:imageView];
[scrollView setContentSize:imageView.frame.size];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have a view in scrolling view, and when I seque(push) from this ViewController to CommentViewController, and came back, view in scroll view moved for 200 px up, I dont know why, I don`t anything in code.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 2000)];
}
Its when Auto Layout is on. When it off, its work, but design is not impressive...
Can I fix it with Auto Layout?
Here's a quick fix
In viewWillDisappear, save the scrollView's contentOffset and reset it to zero.
Later in viewDidLayoutSubview, restore the contentOffset to old value.
Here's the sample code
-(void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if(!CGPointEqualToPoint(CGPointZero, self.contentOffset))
{
scroller.contentOffset = self.contentOffset;
self.contentOffset = CGPointZero;
}
}
-(void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.contentOffset = scroller.contentOffset;
scroller.contentOffset = CGPointZero;
}
My program doesnt even go into the scrollViewDidScroll method. I have no idea why. My view did load looks like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the size of the content to be displayed
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width * ScrollViewControllerNumberOfPages, self.scrollView.bounds.size.height);
// Turn on paging in the scroll view (can also be done in Interface Builder)
self.scrollView.pagingEnabled = YES;
NSLog(#"CurrentPage ViewDidLoad%#",self.pageControl.currentPage);
switch (self.pageControl.currentPage)
{
case 1:
[self.minkyImageView setImage:[UIImage imageNamed:#"monkey_1.png"]];
NSLog(#"case1");
break;
case 2:
[self.minkyImageView setImage:[UIImage imageNamed:#"Shape1.png"]];
NSLog(#"case2");
break;
default:
break;
}
}
Also i have implemented the scrollviewDelegate on my interface like this. I don't see what i am doing wrong. It doesn't even go into the method called scrollViewDidScroll.
#interface MinkyScreenSwapViewController: UIViewController <UIScrollViewDelegate>
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat contentWidth = scrollView.bounds.size.width;
CGFloat halfContentWidth = contentWidth / 2;
NSInteger currentPage = (scrollView.contentOffset.x + halfContentWidth) / contentWidth;
self.pageControl.currentPage = currentPage;
NSLog(#"CurrentPage");
}
Try out:
self.scrollView.delegate = self;
Hope this helps.
Try these codes
scrollView.delegate = self;
scrollView.userInteractionEnabled=YES;
If you are adding scroll view over image view, you have to explicitly set
imageView.userInteractionEnabled=YES;
For more convenience set
[[scrollView superView] setUserInteractionEnabled:YES];
These will make your scrollView delegate method active.