Rotate a UIButton with an angle by a new anchorPoint - swift

I'm trying to Rotate a button basically with a new anchorPoint. Normally anchor points are right in the center of the views. So I want to change the anchor point to right bottom of the frame of my Button.
I've tried to set an anchor point to the right bottom corner of the button frame and tried to rotate the whole button for 60 degrees to right hand side. It does rotate with the code below. But the rotation seems a bit random to me.
What I wanted was rotating a button with an anchor point(which is right bottom point of the button frame) and rotation angle is meant to be 60 degrees to the right hand side
So here is my basic code.
override func viewDidLoad() {
super.viewDidLoad()
let anchorPoint = CGPoint(x: 1, y: 1)
LoginScreenSelectionButton.layer.anchorPoint = anchorPoint // setting new anchor
LoginScreenSelectionButton.transform = CGAffineTransform(rotationAngle: 0.33)
}
My code seems logical and pretty easy to me. What is wrong about it?
I've added an image below. What I'm actually trying to do is drawing the shape below. I've drawn triangle images from adobe photoshop and added those photos to my button in swift.
Now I want to get a full circle from those triangle buttons. To do that, what I thought to do was creating each triangle button from the same point. So they will be on the top of each other.
To create a circular shape I wanted to change the angles of each triangle by adding 60 degree difference between each other(while the anchor point is the right bottom of the button frames).
With that logic I thought that I Would get a perfect circular shape which is created by 6 triangle shaped buttons. So by creating this shape I get 6 different buttons which seems to create a circular shape all together.
Is that approach logical as well?
EDIT: Sorry for long explanation hopefully that will give some information to you about what I'm trying to accomplish
Triangle Button shapes
Thanks

Related

Swift SKCropNode can someone explain this behavior?

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?

Transformation Sprite with finger move

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

Rotate CCSprite around a specific point?

How can I rotate a sprite around a specific point, instead of the center point?
CCSprite rotation or CCRotateTo action rotate around the center point.
I'm trying to rotate the image of a face. Rotating around the center (nose) does not look as good as rotating around a point slightly below the center (chin).
In Photoshop it's possible to change the anchor point for rotation. Can that be done in cocos2d-iphone?
The most obvious way would be to enlarge the size of your sprite.
If the height is 50px, and the current center rotation point is the middle (25px) and you want it to be at say, 30px, just enlarge the canvas of your sprite in photoshop so that the image gained 10px of transparent space at the bottom.
Hopefully this helps your problem, i've never seen an anchor point reference for rotation in cocos2d.
You should change your anchorPoint accordingly.
AnchorPoint will be the center of your ccsprite rotation, it starts from left bottom (0.0,0.0) to right top (1,1). To calculate it, get the point position relative to ccsprite, and divide by the sprite size:
//anchorPoint position
float x = myRotationPosition.x/ mySprite.width;
float y = myRotationPosition.y/ mySprite.height;
mySprite.anchorPoint = cpp(x,y);
//rotate mySprite based on new anchorPoint
mySprite.rotation = 90;
Hope that helps

How to handle exact UITouch of image?

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.

iPhone animation: how do I animate the filling up of an area?

Consider a circle. Now consider a radius of the circle, drawn from the center of the circle towards the right. Now imagine that the radius is rotating about the center of the circle, sweeping out an area as it rotates. My problem is: I want to use iPhone's animation techniques to fill up the swept out area with a different color from the background area of the circle, as the radius rotates from 0 degrees to any chosen number of degrees about the circle.
I've looked through the Core Animation API, KeyFrame Animations, etc. but I am not able to find out how to do this. Any hints will be most welcome.
Thanks,
Sandeep
Check out CAShapeLayer. It lets you animate between two Core Graphics paths, which can be as complex as you want. In this case, you might want to animate between a path which defines a thin filled wedge and a filled wedge that covers a larger angle of the circle. You may need to use a CAKeyframeAnimation to make sure that it is animated in the sweeping motion you desire, and in the direction you want.