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

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];

Related

How to fade the colour of a button to another colour?

I am trying to change a button from one colour (red) to another colour (yellow) when another button is pressed. I currently have an abrupt change from red to yellow, and would like to add in a quick animation to make the transition a bit smoother. How would I go about doing this? Any help would be much appreciated.
UI updates should happen in main tread, but the animation method is in UIView, it is meant to this:
[UIView animateWithDuration:desiredDuration animations:^{
object.property = newValue;
}];

UIButton inside a UIView not working after UIView is animated

I have seen many questions in this forum which gives answer to this topic "UIButton inside a UIView, when animated doesn't work", but after having tried out the answers like
a) UIViewAnimationOptionAllowUserInteraction to the options
b) subView.setUserInteractionEnabled = YES
c) [button addTarget:self action:#selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
none of them is working for me :-(
Here is the scenario. App is in landscape mode and a UIView called menuView is placed at x=480,y=0. Its height=200 and width=150. So, when I tap the button on the top right corner, the following code is executed
- (IBAction)showMenu {
[menuView setUserInteractionEnabled:YES];
[optionsButton setUserInteractionEnabled:YES];
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationCurveEaseOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
self.view.frame = CGRectOffset(self.view.frame, 0, 200);
}
completion:NULL];
}
Output?: View is appearing, but optionsButton inside the menuView is not clickable. I hooked up to an event, did an NSLog(#"Options button clicked"), but nothing happens :-(
Please tell me what I am doing wrong?
Update: When I place the subview that is "menuView" inside the self.view, then upon running and click the optionsButton, I get the NSLog message. Only if I specify the origin.x of menuView to be 480 and above, it doesn't work.
If you can see the UIButton, its userInteractionEnabled (YES by default!) is set, and its superview's userInteractionEnabled in the whole hierarchy is YES - you should be able to interact with it.
An animation will never change your userInteractionEnabled property! So what you are doing there is simply unnecessary. If you try to enable interaction during animation - that's a different story and is just an option passed to the animation message.
So if that's not your problem (and is probably not), then I guess one of the superview's frame is cropping the UIButton!
Now you see, if a UIButton (or any UIView) is outside a UIView's frame, it can still be visible, unless clipsToBounds is set on the superview.
And the outcome of that situation is: You can see me, but you can't touch me.
In my case missing a constraint on the height of the containing view caused the view height to be 0. Buttons were visible, below the view, but untouchable.
For me it was all about an overlooked mistake in the animation code itself. Where my new height was being called I was actually calling my new width, and where my new width was being called I was actually calling my new height, therefor causing the UIView to be super long yet super narrow, thus pushing all content within the center of view, outside of the view reach.
Change your UIViews background color to Red so that you can actually see where it animates to.
If your UIView is within another view, turn on clipSubviews so that you only see what is actually enabled within the subView.
Run your project.
If your UIView is not its normal height and width, more than likely you have overlooked some code in your animation call.
Make sure that your x, y, width, height are being shown in the correct orders within the animation code.
In my case, it seems like my animated transitioning is not yet completed. I forgot to to put completeTransition:Bool at the end of my animateTransition:context method.

How to pinch view on button press?

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

Flip UIView with thickness (like iBooks)

I'm making a reversi clone, and trying to add some thickness when I flip the buttons (Like iBook transition view).
Right now, I use this code to flip the buttons on the board:
[UIView transitionFromView:whiteView toView:blackView duration:0.5f options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){}];
I found a project on github that have implemented this, but I can't get it to work with a child view added to the main viewController.
How do you add the transition to just flip a view, and not transition to a new viewController?
Thanks in advance
https://github.com/epatel/EPGLTransitionView

Animate UITextViews

I have a View with one UITextView in the top half, one UIImageView on the bottom half and a button in the middle, between them. What I'm trying to do is every time I press the button, the UITextView must change the text (it gets it from a sqlite db). I managed to do that, but now I want to animate the text change. So I want the UITextField to fade out to the left, then fade in from the right with a the new text inside.
Now i followed the ViewTransition documentation and created a second UITextView so I can animate between them. The only problem is that animation happens to the entire view. So even the image and the button slides in every time. I just want to animate the text view(s).
How would i go about doing that?
[UITextView beginAnimations:nil context:NULL];
[UITextView setAnimationDuration:0.5];
self.firstTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
self.secondTextView.transform = CGAffineTransformMakeTranslation(-100, 0);
[UITextView commitAnimations];