How to pinch view on button press? - objective-c

I've got the button on the fullscreen UIImageView and I want to pinch this view on that button press. I mean, I want to show only the part of the UIImage to the fullscreen after the button is pressed. Which method should I use?

Basically you can just start a zoom Animation, if that is all what you want.
Example:
[UIView animateWithDuration:1.0 animations:^{
yourView.transform = CGAffineTransformMakeScale(2.0,2.0);
}];

Put your UIImageView inside a UIScrollView to get zooming and panning.
See this SO post. I've already used this technique and it's the only way I know to do it.

you will want to use the pinchGestureRecognizer :)
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIPinchGestureRecognizer_Class/Reference/Reference.html

Related

Event to hide UIDatePicker

I've got UIDatePicker on UIViewController.
After user selected the date and clicked outside the UIDatePicker I would like hide UIDatePicker like:
-(void)hidePicker
{
[UIView beginAnimations:#"SlideOutPicker" context:nil];
[UIView setAnimationDuration:0.5];
[_datePicker setCenter: CGPointApplyAffineTransform(_datePicker.center, _datePicker.transform)];
[_datePicker setTransform:CGAffineTransformMakeTranslation(0, 0)];
[UIView commitAnimations];
}
I try
[_datePicker addTarget:self action:#selector(hidePicker) forControlEvents:UIControlEventTouchUpOutside];
but event doesn't happen, can you get me some advise?
I don't wanna use UIControlEventValueChanged because DatePicker should not hide each time when user change the date
You cannot use UIControlEventTouchUpOutside for this behavior. In your case you need to create a transparent view or button outside the picker and set action for that to dismiss the picker. Set the background color of this view/button as clear color to achieve this. On tap of the button or view, you might have to dismiss the picker.
UIControlEventTouchUpOutside is mainly used for touching inside the view and moving out the finger. While moving out of the bounds of the view, it triggers the event.
Just check if the touch is not inside the bounds of the UIDatePicker each time you touch the screen.Have you tried to set hidden=YES; ? I guess you can change its visibility inside the animation block. BTW, if you're developing for iOS 4+ then you'd better use new (they're actually not new any more) UIView class methods methods for animations because using beginAnimations and commitAnimations blocks is discouraged by Apple. Below are those methods I mentioned:
animateWithDuration:animations:
animateWithDuration:animations:completion:
animateWithDuration:delay:options:animations:completion:
More information in http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111

Flip vertical UIWebview to be shown when view did load

I was searching information to show a uiwebview using a flip horizontal effect like modal transition one in viewDidLoad event, but I wasn't successful, even in apple documents. Can anybody help me with that?
Many thanks
the transition to animate webView with the view add your webView like this.
[UIView transitionWithView:poster.view duration:3
options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self.view addSubview:yourWebView];
}
completion:NULL];
The animation you want to add can be done on the UIView. So you should addSubView the UIWebview to the UIView and then do the animation on the UIView.

Rotating UITabBarController Icon

I have an UITabBar in my application. One of the tab bar icons looks like a loading symbol. When the user presses the loading button I want the icon to spin/rotate until the loading is done. Should I use UIImageView to animate or something else? How should I make this happen?
Jacos, unfortunately you cannot do that with the UITabBarController and manipulate the tabBarController's tabBar properties. My best bet would be that you use a UIToolBar and assign a black color and make it appear like a tabBar and have buttons added in them as a subView so that they look like tabBarItems.
Its much more customizable, and you can even provide a scrolling experience and add more buttons to it.
I know this question is 4 years old but I had the same problem and managed to fix it by reading the tutorial in here:
https://medium.com/#werry_paxman/bring-your-uitabbar-to-life-animating-uitabbaritem-images-with-swift-and-coregraphics-d3be75eb8d4d#.bjfpbdnut
The main point is to get the view for desired UITabBarItem and the get the UIImageView from it in viewDidLoad:
UIView *plusView = self.tabBar.subviews[1];
self.plusImageView = plusView.subviews.firstObject;
self.plusImageView.contentMode = UIViewContentModeCenter;
Then in didSelectItem method you can do this:
[UIView animateWithDuration:0.4 animations:^{
[self.plusImageView setTransform:CGAffineTransformMakeRotation(M_PI/4)];
}];
My code only rotate the image view for 45 degrees but you can change as you wish.
I guess you could change the UITabBarItem's icon on a timer, but that seems pretty kludgey. You would have to pre-render each frame of your "loading" icon rather than rotate an ImageView.
Another hackey solution would be to add your ImageView to the UIWindow and move it on top of the TabBarController's TabBar (adding it to the TabBar itself is asking for trouble).
You shouldn't try to animate the actual UIImageView within the UITabBarController. I would take this approach:
Set the image for the relevant tab to nil or a blank image.
Create a UIActivityIndicatorView and add it over the tab bar. Position it over the correct tab.
[self.tabBarController.tabBar addSubview:activityIndicatorView];
When your loading task has completed, restore the normal image to the tab and remove the activityIndicator from the tab bar.

How can I implement a pointer arrow on a toolbar in iOS?

I'm looking to implement a pointer arrow above the currently selected toolbar icon much like the design found in Reeder and Instacast:
The pointer arrow should move across smoothly when another toolbar item is pressed. I need to be able to choose which items cause the arrow to move, as featured in Instacast and Reeder, where only certain items change the arrow position.
Can I do this without too much overhead and a lot of UIKit subclassing?
This shouldn't be too bad: just take an image of the little triangle like you have in your question, and put it in a UIImageView that sits above the toolbar.
Then set it up so that when the action: for the relevant toolbar button is called, the UIImageView slides so that it's in the right place, with animation. Something like:
[UIView beginAnimations:#"TriangleAnimation" context:NULL];
[UIView setAnimationDuration:0.25];
triangleImageView.frame = //new location here
[UIView commitAnimations];

How can I start animating an UILabel from a particular location in iPad?

I need to start animating a UILabel when a button is pressed... the animation should start from the position of the button.
How can I achieve this?
i.e moving label from one end of the screen to another end.
This is acheviced with UIView's animateWithDuration methods, which can be found in the documentation here.
A very simple example which should be called when your button is pressed:
[UIView animateWithDuration:0.5 animations:^{
// set new position of label which it will animate to
myLabel.frame = CGRectMake(x,y,width,height);
}];