gpt4 book ai didi

xcode - 旋转动画 xcode iphone

转载 作者:行者123 更新时间:2023-12-03 18:16:00 26 4
gpt4 key购买 nike

我试图在 xcode 中使用一个简单的单 View 应用程序将图像绕一圈旋转。我在主 Storyboard上有一个圆形图像和一个按钮。我使用以下代码,但圆形图像在旋转时向右下移,然后向左移动。我不确定它缺少什么。

谢谢你的帮助。

View Controller .h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
IBOutlet UIImageView *theImageView;
IBOutlet UIButton *theButton;
NSTimer *theTimer;
float angle;
BOOL runStop;
}


@property (atomic, retain) IBOutlet UIImageView *theImageView;
@property (atomic, retain) IBOutlet UIButton *theButton;

-(IBAction)runRoulette:(id)sender;

@end

View Controller .m
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize theButton, theImageView;


- (void)viewDidLoad
{
angle = 0;
runStop = FALSE;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(void)rotateRoulette
{
theImageView.center = CGPointMake(self.theImageView.center.x, self.theImageView.center.y);
theImageView.transform=CGAffineTransformMakeRotation (angle);
angle+=0.001;
}


-(IBAction)runRoulette:(id)sender
{
if(!runStop)
{
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/600.0 target:self selector:@selector(rotateRoulette) userInfo:nil repeats:YES];
}
else
{
[theTimer invalidate];
theTimer = nil;
}
runStop = !runStop;
}
@end

最佳答案

我找到了一种非常简单的方法来让我的动画按照我想要的方式工作 -

theImageView.center = CGPointMake(160.0, 364.0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
//theImageView.center=CGPointMake(self.theImageView.center.x, self.theImageView.center.y);
theImageView.transform = CGAffineTransformMakeRotation(M_PI/2.65);
[UIView commitAnimations];

它旋转 theImageView M_PI/2.65(M_PI/2.65 是旋转量),计数为 5。

关于xcode - 旋转动画 xcode iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14300851/

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