Zoom multiple UIimageview inside the dynamic UiscrollView without taking any main container view for paging view - ios

How to zoom ScrollView along with all its content without taking main container view.
I am working on a app where i have to show two image in a scrollview dynamically like a pager view for 80 images coming from url.i am able to show two images(like pages of book) in scroll view and i want to zoom both image in the scroll view simultaneously without taking any main container view.

I think it can be achieved by doing something like below
[UIView animateWithDuration:.2 animations:^{
imageView.transform=CGAffineTransformMakeScale(self.scrollview.zoomScale, self.scrollview.zoomScale);
}];
Note: Code has not been tested, please try, and update.
Update
for(UIView *subview in self.scrollView.subviews){
for(UIImageView *imageView in subview.subviews){
[UIView animateWithDuration:.2 animations:^{
imageView.transform=CGAffineTransformMakeScale(self.scrollview.zoomScale, self.scrollview.zoomScale);
}];
}
}
Cheers.

Related

Navigation drawer- sliding issue in ios

I am trying to create a sliding menu (like the one in google maps app) in which menu screen should be shown or added as subview over the existing screen on tapping a button. While showing it, the sub view should be animated from left to right. I tried to animate while adding it as subview, but failed in doing so. Can any one suggest how to do it? (or) Can I do it using navigation controller?
Thanks in advance!!
You need to add the subview, and set it's frame out of the screen.(320,0,100,568 for example).
Of course it's better to use auto layout for that.
Add as subview:
[self.view addSubView:sideMenu];
When you want to show it, just change it's frame using animation block.
[UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
sideMenu.frame = CGRectMake(220,0,100,568);
} completion:^(BOOL finished) {
}];
As I said, it's better to use auto layout and not setting frames. I did it only for the example.

Hidding view with table scroll

I'm searching for idea how to implement a table view with moving view on top of it.
So the idea is something similar to navBar in facebook app. When you scroll up this (red) view is moving up and hiding, when you scroll up its going up and when you scroll down its revealed. This is not nav bar so most of the pods I've found are not working in this situation. This cannot be tableView header or section header as well.
You need added this view above table:
[self.tableView.superview insertSubview:view aboveSubview:self.tableView]
Or you can do it in storyboard.
When you table scroll down hide view, when up show.
[view setHidden:YES];
Also u could change table inset to the top of the superview.
self.tableView.contentInset = self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.contentInset.top -, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
I think fast way to do it use gesture recognizers to recognize reveal and hide actions and than you can use methods like below,
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:0.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
and for reveal attached view
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:1.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
methods will help you to hide and reveal views gently.
Take a look at this library, it does exactly what you want to do
https://github.com/telly/TLYShyNavBar

With Objective-C, how can I animate the frame position of a bottom layer without affecting top layers?

I have two UIImageView's, one that is a background that should scroll, and one an avatar that should move positions based on user input.
I'm able to move the avatar with no problem, and I'm able to scroll my background when necessary with:
CGRect oldPos = _fieldView.frame;
CGRect newPos = CGRectMake(oldPos.origin.x, oldPos.origin.y - 400, oldPos.size.width, oldPos.size.height);
[UIView animateWithDuration:5.0
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
[_fieldView setFrame:newPos];
}
completion:^(BOOL finished){
NSLog(#"Done with animation");
}];
However, when this _fieldview scrolls, my avatar on top of it scrolls with it. How can I move my background image without affecting the other images?
A few other settings that may affect this:
I've disabled AutoLayout
My background image mode is set to AspectFill
I'm using a storyboard with a single UIView
Thank you for any suggestions.
EDIT
The avatar, runnerView, is added as a subview of _fieldView, with
[_fieldView addSubview:_runnerView];
You want your background scroll image to not be a superview to your avatar, but sibling view instead.
(Not the best representation, not sure how to make it look better though)
-Main View
--Scroll view
--Avatar
i.e.
[self.view addSubview:backgroundView];
[self.view addSubview:avatarView];
not
-Main View
--Scroll view
---Avatar
i.e.
[backgroundView addSubview:avatarView];
[self.view addSubview:backgroundView];
If it is required to be a subview, then you will have to move the avatar view an equal and opposite amount so it will stay in the same relative location.

UIScrollView Jerky Scrolling

I have a big scroll view. I just wish to scroll around the scroll view with fixed steps on every button press. However when I write the following code the scroll view scrolling is very jaggy. Can someone explain why?
CGPoint lstructCurrentPoint = self.objScrollView.contentOffset;
lstructCurrentPoint.x += 400;
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,
lstructCurrentPoint.y,
self.objScrollView.bounds.size.width,
self.objScrollView.bounds.size.height)
animated:NO];
} completion:^(BOOL finished)
{
}];
I do not use the animated:Yes arguement because I need custom scroll speeds between the different contentOffsets.
when you update your scroolview content frame while scrolling with an animation is like you try to update something that is in the past that is already changed... (probably is not the best explanation :D )
try with this in your animation option:
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState
Why don't you just try using
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x, lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
instead of using this within UIView animation function.
Try to use
[self.objScrollView setContentOffset: CGPointMame(lstructCurrentPoint.x, lstructCurrentPoint.y) animated: YES];
instead of scrollRectToVisible.
scrollRectToVisible animated is an animation by itself.
With your current code, you are trying to animate the animation.
Hence it is jerky.
Just use to scroll the rect to visible:
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
No one can properly answer your question without knowing what content you have in the scrollView.
However, you can find out what is causing this yourself.
Profile the app on your device. This will open Instruments. Select the Core Animation tool.
When the app is running scroll the view so that instruments captures the data.
Now the Time Profiler section will tell you exactly what is taking a long time. Fix this and you'll have smooth scrolling.

UIView animation while scrolling a table

I have a UITableView in an iPad, and its right half side is covered with a view.
What I want is: when the user scroll the UITableView, I want the covering view to slide (with an animation) to the right until its origin.x is at the end of the right side of the table, so the UITableView is clear to see (just like in the Twitter app for iPad).
The problem is: You can scroll the UITableView and animate a view at the same time. When I start scrolling, I use didStartDraging and even DidScroll to create a [UIView animate...] method, but this method stuck my scrolling.
I tired with block animation. I tried with Gestures. I tried with CABasicAnimation, and it goes quite OK, but somehow all the UISubview "Touch area" in my sliding view stay at the old place (what I mean is that the view gets its new frame, but I can scroll a UIScrollView, which is a UISubview of my view, even when my finger is out of the superviews frame S-:, even that there is no view at that point on screen.)
Any thoughts how can I make the animation without damaging the scroll of the table? (and I heard about the timer in the K and the runloop common modes. Not so helping)
Thanks.
scrollview Delegate methods will be invoked for tableView also ............
you can use following code it worked for me and hope will work for you also.......
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[UIView animateWithDuration:0.3 animations:^{
[scrollView setFrame:CGRectMake(50, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height)];
}];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[UIView animateWithDuration:0.3 animations:^{
[scrollView setFrame:CGRectMake(100, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height)];
}];
}
set x position of scrollView(tableView) as your requirement......
Have a happy coding....

Resources