I was thinking of make a slider/joystick but not in a circle but in a line. So I made the image drag able only over the X axis and when it gets to the point where the slider stops i did this :
if(slider.center.x <= 60) {
slider.center = CGPointMake(60, slider.center.y);
}
so it wouldn't get bigger than 60 but i was thinking isn't there a better way to do this? like make a box and setting up something to not drag it outside that box?
Thanks!
I think this method is very good. As far as I know there is no wan to stop dragging in other ways than this.
However there is a control called UISlider. This control does the functionality you would like to have.
You could also use touchesBegan, touchesMoved, and touchesEnded, then add an image behind and detect when touch is less than half image's width (Left) or when it's greater than half (Right)
Related
I'm having trouble to implement something like the image attached. Basically, I want the progress of the snail away from the flag to be displayed on my HUD. (take a look at the game window of the editor, upper center)
I'm guessing I just need to scale the distance from the moving object to the flag but I have no idea how. Or I need a new camera for it? Please help!
Thanks!
Here is my problem: I developed an App that split fairly teams for a soccer game. It also can count the goals of each player. The player that makes a goal has his level up. I want an animation that shows the star been filled. How can I do this?
Depends on the way you want your animation to look like.
My suggestion is to make a empty star (just a border) and make it full size. Then add another on top of it (thats filled).
Before the animation starts you need to resize that star so it's nonexistent (width and height are zero)
filledStar.transform = CGAffineTransformMakeScale(0, 0)
and then animate it to full size like this
UIView.animateWithDuration(0.5) {
filledStar.transform = CGAffineTransformIdentity
}
You can also play around with spring animations so it over extends and then goes to full size, but that is up to you.
Treat the star shape as a mask and animate the movement of a colored view behind it, as I suggest in this answer (where what is being filled is an apple, not a star, but it is the same technique):
https://stackoverflow.com/a/29553645/341994
I am trying to created a vertical menu (on the left side of the screen) which I can display and hide using a gesture recognizer.
I have found a post similar to this which helped slightly, but all it did was rotate the UIToolBar to a vertical position without changing the width or position.
If anyone has succesfully created something similar to this and is willing to help I would greatly appreciate it!
Also, if anyone can point me in the right direction possibly to some sample code I would like that as well.
You could do this with a UIToolBar by applying a 90 degree rotation transform, and then having all your icons rotated 90 degrees to match - you can change the width and position simply by adjusting the UIToolBar frame. However, you will need to create your own toolbar to do this rather than using the built-in one you get with a navigation controller.
Another option is simply to roll it yourself: this will allow you more customisation, so is perhaps the better option. There are a number of third-party implementations of varying types, some based off the current Facebook App side-bar, a good place to start looking is http://cocoacontrols.com - they are of varying quality.
On the other hand, it wouldn't be too difficult to roll your own, so that's a good option to consider.
I have a graphic that is 3 times the width of an iphone landscape view.
I am trying to auto scroll it so that it appears that it is moving sideways, without using the touchscreen scrolling method.
My aim is to maybe have a button you can press and it moves it left or right across the screen like an animation.
I can deal with everything else but am having trouble finding a solution.
Any example code would be appreciated or even any info on whether it is possible or not.
Thanks. Dave
You can wrap a UIView in an animation block. The animation sweeps the origin value in its frame property from one point to another, over a set period of time.
I have custom slider that I use the following touch event to respond to:
[bSlider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
I find it very difficult to use, it does not respond to touches about 50% of the time. Compared to the volume slider with the music player that works great every time you touch it. Are there any secrets to creating a slider in code that will make it more responsive?
I had the same problem with my custom UISlider and solved it by using a larger "thumb" image with transparency around the outside.
I also had problems with my callback function running slowly and causing the slider to be very laggy and clumsy to use, which I fixed by adding a simple check at the top of the function:
int val = ceil(sliderView.value);
if (val == _lastSliderVal) return;
_lastSliderVal = val;
// .. code to update various display elements based on slider value
After changing both of these, the slider works beautifully.
The problem is the event you are tracking. UIControlEventTouchUpInside means that your -start method will only get called if you lift your finger up while it is still in the bounds of the control, something that's not easy to do on a slider.
What you probably want is UIControlEventTouchUpOutside and/or UIControlEventTouchDragExit, which will call -start either when you lift your finger outside of the control's bounds, or when your finger is dragged from within a control to outside its bounds, respectively.
See the UIControl reference for more info.
Well I tried several things including the suggestions above but never got my slider to work as well as the iPhone volume slider in the music app. The only thing that helped was to add a clear background around the button image to make the touch space larger. That created problems getting the button to slide all the way to the bottom and top of slider that I never completely resolved. Now with OS 3.0 is seems to be working much better.