Cocoa touch 如何旋转UIImageView?
我对Xcode非常陌生,我想知道如何在触地时旋转uiimage,这是我目前拥有的:Cocoa touch 如何旋转UIImageView?,cocoa-touch,uiimageview,Cocoa Touch,Uiimageview,我对Xcode非常陌生,我想知道如何在触地时旋转uiimage,这是我目前拥有的: @implementation secondViewController int degrees; UIImageView *gliderImageView; bool continueSpinning; -(void)startSpinning { degrees = 0; continueSpinning = true; [s
@implementation secondViewController
int degrees;
UIImageView *gliderImageView;
bool continueSpinning;
-(void)startSpinning {
degrees = 0;
continueSpinning = true;
[self continueSpinning];
}
-(void)continueSpinning {
degrees = (degrees + 1) %360;
CGAffineTransform rotate = CGAffineTransformMakeRotation( degrees / 180.0 * 3.14);
[gliderImageView setTransform:rotate];
if(!continueSpinning) return;
else [self performSelector:@selector(continueSpinning) withObject:nil afterDelay:0.1f];
}
-(void)stopSpinning {
continueSpinning = false;
}
有人知道吗
如何将按钮链接到图像
如何使用按钮设置布尔值
这个代码一开始是否有效?
您可以找到旋转UIImage的示例 在你的.h中写下: 在@界面中
IBOutlet UIImage *myImage;
IBOutlet UIButton *myButton;
在@interface结束括号之后
@property (nonatomic, retain) IBOutlet UIImage *myImage;
@property (nonatomic, retain) IBOutlet UIButton *myButton
-(IBAction) spinIt:(id)sender;
然后在你的.m中写下:
在“实施”框架下:
@synthesize myImage, myButton;
然后在viewDidLoad的末尾下面写下如下内容:
-(IBAction)spinIt:(id)sender {
myImage.image = image;
[self addSubview:imageView];
CGAffineTransform rotate = CGAffineTransformMakeRotation( 1.0 / 20.0 * M_PI );
[imageView setTransform:rotate];
}
以上代码来自
之后,将图像和按钮添加到情节提要中的视图中,并通过控制从按钮拖动到响应器并单击spinIt方法,以及通过控制从“连接”选项卡最右侧的“小箭头”图标下的“出口名称”拖动到各自的连接来设置引用
上面的代码旋转90度,因此您可能需要更改它以满足您的需要。此外,这是一个重复的问题,所以在未来请在发布前搜索。祝你好运
编辑-如果您希望在按下按钮时图像旋转,我建议在旋转过程中以不同的间隔制作一组图像,并像停止运动动画一样播放图像。有关这方面的说明可在[此处]找到