I am implementing a custom segmented controller via two buttons. Each will be a circle, and the selected one will be filled. I would like to animate the selection of a button so that the "fill" appears to move from one to the other. What is the best way to accomplish this? Should I just use a UIView behind?
Related
I'm trying to divide one image to a more than one clickable part. for example, if the image is a body image, and I tapped the head, it should take me to a different the HeadViewController, but if I tapped on the left hand, it should take me to a different view controller
Any idea how to do that?
Easy method:
Add UIButtons on top of the image with clear background color. You can do this with AutoLayout and always get correct proportions to the areas when scaling up and down.
Hard method:
Add UITapGestureRecognizer to the UIImageView and calculate CGPoint depending on where it the touchPoint is received. This is complicated and must be calculated correctly.
For you, I suggest the first method suggested.
Attach a tap gesture recognizer to your image view. Set user interaction enabled to true.
In the handler for the tap gesture, fetch the coordinates of the user's tap and write custom code that figures out which "hot box" the user tapped in.
Alternately you could create a custom subclass of UIGestureRecognizer that has multiple tap regions.
I was trying to use iCarousel for one my app, I need to achieve something like the image below
How to animate sliding Item 2 to Item 1? How to animate the change of distance between the elements?
Animation show only first time when open, then iCarouselOptionSpacing will be always the same.
Wondering if the above can be created using UISlider? If not, what other ways can this be accomplished?
You can set components of a UISlider, such as the currentThumbImage ( see: "Appearance of Sliders"1).
However, it is almost certainly easier to just re-implement a slider for this much customization. Simply use background UIImageView with the scale image, and then add a separate UIView (or UIImageView) for the arrow. Finally, attach a UIPanGestureRecognizer to the arrow view to allow a user translate the view vertically.
You can change a lot in the appearance of a UISlider like setting the thumb to a red arrow. You can also replace the background image with the inches ruler and with different rulers for the different device types and display sizes.
The one thing that I don't see is that you turn the slider to work vertically. I know them only working left to right.
If I'm right, your only chance is to have a ruler as background image and a view that contains the arrow and a label with the actual value. That whole view can be pawned and tapped using Gesture Listener.
I am trying to place a UIButton inbetween my popup view and the parent view.
I cant successfully do that by doing that [self.view addSubview:new];. My problem there is the border UIView can be seen across the UIButton .
I've tried [self.view.superview addSubview:new]; thinking that that would make it go away but it doesnt it still shows there.
I need to find a way to successfully place that button on top of everything (UIView border in this case).
I know I could do that if I insert the button from the parentView, but I want to handle all my subViews buttons within each subView, otherwise it everything will become messy very quickly.
Is there a way to do what I am trying to achieve?
According to Apple's CALayer documentation, borders always appear above subviews because they're drawn on another layer. The best solution is to create a background view to fake the border.
So instead, your popup view would have an orange background. It'd have another, slightly smaller subview directly over it with a white background, and then your button.
See this post for the implementation.
I am building a word tetris kind of an app. Now I have to move a Uiview containing 8 uibuttons towards the bottom of the screen based on time and also track the position of uibuttons as the user taps specified button.
Am I suppose to use Block based animation or core animation to do the task.
Currently if I am animating frame and center of superview it seems like I have to do the same for the subviews as well inside the block.
Any input would be handy.
You can use UIView block animation to animate a view and it's subviews quite simply.
However, neither UIView animation nor core animation will let the user click on buttons as they are animating. Button actions don't work at all on "in flight" animations. There's no automatic way to do that. (At least none that I know of.)
Instead, you have to add a tap gesture recognizer to the parent view, and do hit testing on the presentation layer of your parent view to see which sublayer of the presentation layer is tapped.