java 图片绕中心旋转,围绕固定点旋转图像

我不确定图层位置,但是当我更改anchorPoint时,框架会发生变化,所以我会调整框架 .

-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view

{

CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y);

CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y);

newPoint = CGPointApplyAffineTransform(newPoint, view.transform);

oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);

/*

CGPoint position = view.layer.position;

position.x -= oldPoint.x;

position.x += newPoint.x;

position.y -= oldPoint.y;

position.y += newPoint.y;

view.layer.position = position;

*/

view.frame = CGRectOffset(view.frame, newPoint.x-oldPoint.x, newPoint.y-oldPoint.y);

view.layer.anchorPoint = anchorPoint;

}

而且如果你想通过多次调用rotateImage回到原来的位置,我认为你应该只在此之前设置一个锚点 . 因为如果使用相同的rotateImage方法创建两个单独的动画,则将使用当前实现重新计算锚点 .

-(void)rotateImage:(UIImageView *)image

duration:(NSTimeInterval)duration

curve:(int)curve

degrees:(CGFloat)degrees

{

// Setup the animation

// [self setAnchorPoint:CGPointMake(.44,.85) forView:image];

// image.transform = CGAffineTransformMakeRotation(d2r(degrees));

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:duration];

[UIView setAnimationCurve:curve];

[UIView setAnimationBeginsFromCurrentState:YES];

// The transform matrix

CGAffineTransform transform = CGAffineTransformMakeRotation(d2r(degrees));

image.transform = transform;

// Commit the changes

[UIView commitAnimations];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.font.*; public class Clipping extends Canvas { public Clipping() { setBackground(Color.white); } public void paint(Graphics g) { Graphics2D g2; g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; FontRenderContext frc = g2.getFontRenderContext(); Font f = new Font("Helvetica",Font.BOLD,w/8); String s = new String("By"); TextLayout tl = new TextLayout(s, f, frc); float sw = (float) tl.getBounds().getWidth(); AffineTransform transform = new AffineTransform(); transform.setToTranslation(w/2-sw/2,h/2); Shape shape = tl.getOutline(transform); g2.setClip(shape); g2.setColor(Color.blue); g2.fill(shape.getBounds()); g2.setColor(Color.yellow); for (int j = shape.getBounds().y; j < shape.getBounds().y + shape.getBounds().height; j=j+3) { Line2D line = new Line2D.Float( 0.0f, (float) j, (float) w, (float) j); g2.draw(line); } } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} public void windowClosed(WindowEvent e) {System.exit(0);} }; Frame f = new Frame("2D Text"); f.addWindowListener(l); f.add("Center", new Clipping()); f.pack(); f.setSize(new Dimension(400, 300)); f.show(); } } *********************************************

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值