I have an image for example triangle and place it inside UIImageView, and I have a touch and drag application, I can already drag the triangle but my problem is I can still drag the triangle even if I'm not actually touching the triangle, (Im touching the upper left of the triangle image) I think this is because the UIImageView itself is a square so although I have not touch the triangle image but I have touch the square UIImageView that's why I can still drag it w/o touching the triangle,
So the question would be how can I make this accurate, like I can only drag it if I have touch the triangle image and not really the square ImageView?
Hopeful for all your help.
Instead of using UIButton, try using CGPath and testing for CGPathContainsPoint.
Also, try LaMarche's Improved Irregular UIButton.
Otherwise, you could use some trigonometry to determine where the touch occurred and whether or not it is within your internal shape.
Related
I have a grid of 16 SKCropNode objects. Each contains a SKShapeNode used as a mask, and a SKSpriteNoe. In this image with the mask not set you can see all 16 object appear in a grid.
https://github.com/soggybag/Grid
Interaction is strange also. Tapping makes the image sprite move down and disappear moving out of the mask. You can tap the area below the orange, where a sprite would be hidden, and it recognizes the tap event.
Even stranger you not tap the sprite in the upper right?
I am making an Drawing App in someway like Paint in Windows
I have a toolbar with many shapes button such as Rectangle, Circle, Triangle, etc. When tap a button i add a sprite with shape with button's name.
I want to add functions like this
- When tap on shape it show four 4 points each corner of shape that i can touch and drag to skew or scale.
Same as we do with an image in photoshop or MSWord
anyone have sample code or tutorial ?
Use this code for your app.
Paint
Drawing
Drawing2
I want to use triangle type buttons on image but i am unable to do this...
How to do this?
This project can help you. you can customize the shape of the UIButton.
All UIViews - all of them - are rectangles. You cannot make a UIView that is a triangle, but you can make one that contains and presents a triangular shape and responds only to touches within that shape. You must understand of course that underneath it all, it's a rectangle, and you'll have to handle the case wherein the user touches outside of the triangle but inside of the rectangle, probably by passing such events through to views below. Indeed, you might have to handle all touch event combinations (touch down inside, touch up outside, touch move outside, etc) in this way.
Maybe the project referenced above will handle all this, I didn't look too deeply.
I need a 'mask' layer that covers the whole screen, with the center part (a circle) to be transparent. Then I can move the mask layer around using touch. User are only able to see the transparent part in the middle.
I don't think a png file can help because the file need to be very large to cover the whole screen.
So is it possible to do it by coding?
i found this online, but don't know much about openGL. http://www.cocos2d-iphone.org/forum/topic/7921.
it would be great if i can use a CCMaskLayer and input with the radius. i can handle the touch event by my self.
the attached png file is expected result, the center part is transparent. i need this to cover my screen, and only show the middle part. the red part is covered.
I write a CCMaskLayer to do the exactly same thing.
https://github.com/smilingpoplar/CCMaskLayer
You may solve this task with cropped circle texture in two ways:
1) Draw sprite with circle texture in screen center and draw another 4 sprites around (on top, bottom, left and right sides) with small red texture but scaled to cover all screen.
2) (more elegant but harder to implement) Make your mask layer fullscreen but adjust texture coordinates. In details:
set wrap mode to GL_CLAMP_TO_EDGE to your circle texture
adjust texture coordinates of your layer vertices (to do this you need to subclass base CCLayer):
Here v means vertex position and t - texture coordinates. You need to set correct texture coordinates for four corner vertices of layer. For future if you will want to drag circle you will need to add some offset values to texture coordinates.
Ok I have 6 custom UIButtons. Their normal state image are all circles images.
They are all spaced out equally but all the circles touch each other.
The problem with the custom UIbutton (which has a circle image on it), is that the hit area of that button is square, and the corners of this square overlaps the hitarea of the other custom button's hitarea.
How do i make the hit area of a UIbutton whos normal state has a circle image, be only clickable on that circle only, rather than the normal square hit area?!
I hope that someone can find a way for me to solve this problem that i currently am having!
Thanks in advance
Pavan
If the square area of a "circle" is clicked on, you should then check if the distance between the center of the circle and the coordinates of the click are less than the radius of the circle. If not, then the "hit" can be ignored.
Thanks for the input demi, I just basically put hidden buttons on top of the images. They weren't really circles, they were more complex shapes; hence the reason I didn't bother about the maths, so I just placed hidden buttons on top of the images themselves and make those hit areas and cover appropriately until I get the desired hit area coverage I need.
Although not very neat, it works well! :D
Thanks once again for the swift reply demi.
OBShapedButton is an awesome project that will give you a button that will only respond to taps that are in the images area. I've messed with a few projects that say they do the same thing, and this one is the best I've seen so far.