Back-to-back UIScrollView zooming - objective-c

Using OS 3.1 I'm placing a tap-detecting image view (taken from Apple's Scroll View suite samples) in a UIScrollView and want to zoom twice on the image view when it appears. The first zoom is to make the entire image visible and the second zoom is to zoom in to a specified region. What I have right now is:
- (void)viewDidLoad {
// After adding scroll view and image view
imageScrollView.minimumZoomScale = 0.5;
imageScrollView.maximumZoomScale = 2.75;
imageScrollView.zoomScale = 1.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate: self];
[imageScrollView zoomToRect:[imageView frame] animated:YES];
[UIView commitAnimations];
and the following to detect the end of the first zoom and to trigger the second:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
selectedRect.origin.x = 60.0;
selectedRect.origin.y = 90.0;
selectedRect.size.width = 90.0;
selectedRect.size.height = 90.0;
imageScrollView.minimumZoomScale = 1.0;
imageScrollView.maximumZoomScale = 2.75;
imageScrollView.zoomScale = 2.5;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate: self];
[imageScrollView zoomToRect:selectedRect animated:YES];
[UIView commitAnimations];
What happens is that this causes an infinite loop and the scroll view "wiggles" repeatedly between two zoomed-in points. What should I be doing differently? Thank you.

Surely you just need to check the current zoomScale as the first action in scrollViewDidEndZooming. If you are already zoomed in, don't do your new zoom.

Related

Programmatically reposition a UIWebView when iAD hides

I am trying to add an iAD banner to my project, and if an error occurs I will hide the banner. This cause's a blank space no naturally I wish to move the UIWebview up to fill that space. The problem is I can't seem to reposition the webview. (I am using interface builder to set the original position).
This image illustrates my layout:
Here's the code I've been trying to use to reposition which is placed in viewDidLoad:
//iAd
_WebsiteiADBanner.delegate = self;
[_WebsiteiADBanner setHidden:YES];
CGRect oldFrame = self.webView.frame;
CGRect newFrame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y-44, oldFrame.size.width, oldFrame.size.height);
[self.webView setFrame:newFrame];
[self.webView reload];
You souldn't place that code in ViewDidLoad, because it only loads once. Instead you must place it in the iAd functions in it's delegates. (make sure your iAd view has set that viewController as its delegate). The following example will do it animated (haven't tested yet):
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
//hide the banner and move the webview
[banner setHidden:FALSE];
CGRect newFrame = CGRectMake(0, 44, self.webView.frame.size.width, self.webView.frame.size.height);
[self.webView setFrame:newFrame];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
//show the banner and move the webview to the top
[banner setHidden:TRUE];
CGRect newFrame = CGRectMake(0, 0, self.webView.frame.size.width, self.webView.frame.size.height);
[self.webView setFrame:newFrame];
[UIView commitAnimations];
}

iOS Sliding Animation Happens Twice Unwantingly

I'm working on a page-based iPhone app using Xcode 4.4 with ARC and have been stuck on this for awhile. On a certain page, a UIImageView finger needs to slide up and point to something and then slide left off the screen. This works as expected when I run it once, but when I turn the page and go back - there is now 2 fingers sliding about 0.5 seconds out of sync with eachother.
Here's the code:
-(void)fingerSwipeUp:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(213.75,355.5)];
[UIView commitAnimations];
}
-(void)fingerSwipeLeft:(UIImageView *)imageView
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[imageView setCenter:CGPointMake(-80,355.5)];
[UIView commitAnimations];
}
UIImageView *finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"finger.png"]];
// position finger off the screen
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
[self performSelector:#selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:#selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
Any help greatly appreciated
I'm guessing that you're creating the "finger" view in ViewDidAppear()? If that's the case, every time the page is turned (hidden) and then gone back to, you're adding another arrow (subview). What about this instead:
if (finger == nil) {
finger = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"finger.png"]];
[finger setFrame:CGRectMake(142.5,480,152.5,243)];
[self.view addSubview:finger];
}
[self performSelector:#selector(fingerSwipeUp:) withObject:finger afterDelay:6];
[self performSelector:#selector(fingerSwipeLeft:) withObject:finger afterDelay:8];
If you've got a number of animations in a sequence, you might find it easier to use the block-based UIView animation syntax:
[UIView animateWithDuration:1.0 delay:6.0 options:UIViewAnimationCurveEaseInOut animations:^{
// animation 1
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.0 delay:8.0 options:UIViewAnimationCurveEaseInOut animations:^{
// animation 2
}];
}];
This will only start animation 2 after animation 1 has finished, so you don't need to worry about allowing for the duration of animation 1 when delaying animation 2.

how to animate a UIView same as the working of presentModalViewController ( ie [self presentModalViewController:child animated:YES];)

I am new in ios development, Now i am doing some animation on my application.In my application has one menu on the bottom of main view and have two button one for hide the menu and other for show the menu .My needs is the show and hide function of menu is working like
the [self presentModalViewController:menuView animated:YES]; and [self dismissModalViewControllerAnimated:YES]; function(ie. click the show button ,pop the menuView from the bottom of main view and click the hide button ,move down the menuView ) . I know the basic animation like:
[UIView beginAnimations:#"ShowHideView" context:nil];
[UIView setAnimationCurve:UIViewAnimationOptionOverrideInheritedCurve];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[menuView setAlpha:0];
[UIView commitAnimations];
If any body know ,please help me.
When you tap showMenuView, do as following,
- (IBAction)showView:(id)sender
{
[self.view addSubview: menuView];
CGRect rect = menuView.frame;
rect.origin.y = 480;
menuView.frame = rect;
[UIView beginAnimations:#"ShowView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.y = 0;
menuView.frame = rect;
[UIView commitAnimations];
}
And to hide,
- (IBAction)hideView:(id)sender
{
CGRect rect = menuView.frame;
[UIView beginAnimations:#"HideView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
rect.origin.y = 480;
menuView.frame = rect;
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[menuView removeFromSuperview];
}

animate multiple images simultaneously

I have five images, and all i need is to animate them differently and simultaneously on the screen. I got different animation codes but they use sequence of images to create animation .. or they animate a single image. Please help
Thankyou so much #Rob and #Aadhira for your interest. Here is my code that moves one image linearly.. How can i animate it in a curve
if(isAnimate) {
NSLog(#"+30,+15");
[UIView beginAnimations: #"moveView" context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
searchLight1.frame = CGRectMake(searchLight1.frame.origin.x+30, searchLight1.frame.origin.y + 15, searchLight1.frame.size.width, searchLight1.frame.size.height);
[UIView commitAnimations];
isAnimate = NO;
}
else {
NSLog(#"-30,-15");
[UIView beginAnimations: #"moveView" context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.5];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
searchLight1.frame = CGRectMake(searchLight1.frame.origin.x-30, searchLight1.frame.origin.y -15, searchLight1.frame.size.width, searchLight1.frame.size.height);
[UIView commitAnimations];
isAnimate = YES;
}
It all depends on what kind of animation you want and what code you are having. If you post that, it would be better.
Anyhow you know how to animate a single image. Then start animating the 5 images in 5 different blocks.

UIView animation change size of button

I started trying to recreate the buy button from the app store which requires a 2-stage click to buy something. I to animate the button expanding. So far I have this
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
[UIView commitAnimations];
which just causes the button to become larger, it doesn't animate at all. Have I done something wrong or has anyone else implemented this type of button behaviour?
EDIT:
- (IBAction) buyButtonAction: (UIButton *) sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
sender.clipsToBounds = NO;
sender.frame = CGRectMake( CGRectGetMinX( sender.frame) - 30, CGRectGetMinY(sender.frame), 200, 37);
[sender setTitle:#"Touched Touched Touched" forState:UIControlStateNormal];
[UIView commitAnimations];
}
Are you targeting an iOS that doesn't support Blocks?
I've implemented a "button animates on touch" using the following nauseatingly simple code.
[UIView animateWithDuration:0.5 animations:^{
self.navigationItem.rightBarButtonItem.title = #"Quoting...";
}];
Alternatively, this code seems to work as well to animate a button on touch, if you can't support blocks (it also includes the blocks commented out if you go that route):
-(IBAction) clicked:(UIButton*)sender{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//[UIView animateWithDuration:2.5 animations:^{
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
//sender.frame = CGRectMake( CGRectGetMinX( self.theButton.frame) - 100, CGRectGetMinY(self.theButton.frame), 300, 40);
//[sender setTitle:#"Touched Touched Touched" forState:UIControlStateNormal];
//}];