gpt4 book ai didi

ios - 移动 imageView 时旋转它

转载 作者:行者123 更新时间:2023-11-29 12:53:17 25 4
gpt4 key购买 nike

所以我有一个名为 image 的 UIView,我试图在我上下移动 View 时让它旋转,这是我到目前为止所做的,但它使图片旋转而不是下降:

{
return centerY - height / 2 <= 10 ||
centerY + height/ 2 >= self.view.bounds.size.height - 10;
}

-(void)moveUpDownTimerCallback
{
[UIView commitAnimations];
verticalSpeed += acceleration;
degrees+=degreechange;
CGSize sz = image.bounds.size;
image.transform = CGAffineTransformMakeRotation(degrees * M_PI/180),image.layer.anchorPoint =
CGPointMake(rotPointx/sz.width,rotPointy/sz.height);rotPointy = image.center.y;
rotPointx = image.center.x;

CGPoint newCenter = CGPointMake(image.center.x, image.center.y + verticalSpeed);
if ([self hasCollided: image.center.y + verticalSpeed imageHeight:
image.bounds.size.height]) {
acceleration = 0;
[self moveUpDown: 0];

}
else {
image.center = newCenter;
}
}

-(void)moveUpDown:(int) vSpeed
{
verticalSpeed = vSpeed;
if (verticalSpeed != 0 || acceleration != 0) {
if (timer == nil)
timer =[NSTimer scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(moveUpDownTimerCallback)
userInfo:nil
repeats:YES];
}
}
else {
if (timer != nil) {
[timer invalidate];
timer = nil;
}
}
}

任何帮助将不胜感激(:

最佳答案

试试用这个方法旋转imageview

        CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = @0.0f;
animation.toValue = @(2*M_PI);
animation.duration = 1.0f; // this might be too fast
animation.repeatCount = HUGE_VALF; // HUGE_VALF is defined in math.h so import it
[self.imageview1.layer addAnimation:animation forKey:@"rotation"];

用这个方法移动 View

CGRect frameBottomview1 = self.yourview.frame;
frameBottomview1.origin.y = 300;
[UIView animateWithDuration:0.7 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.yourview setFrame:frameBottomview1 ];

} completion:nil];

enter image description here

关于ios - 移动 imageView 时旋转它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com