我是法国人,请原谅我的英语.所以我使用加速度计,但在我的代码中,加速度计适用于视图而不适用于图像.我想要做的是将此加速度计用于图像而不是视图.我怎样才能做到这一点?这是代码:
#define CONST_fps 100.
#define CONST_map_shift 0.01
#define kFilteringFactor 0.1
UIAccelerationValue rollingX, rollingY, rollingZ;
@implementation MapViewRotationViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// accelerometer settings
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / CONST_fps)];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor));
rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));
float accelX = acceleration.x - rollingX;
float accelY …Run Code Online (Sandbox Code Playgroud) 大家好我是法国人因为我的英语而烦恼我这里是我的问题:我们如何定义视图的高度和宽度.这里它的名字是flakeView.这是代码:
UIImageView* flakeView = [[[UIImageView alloc] initWithImage:flakeImage] autorelease];
// use the random() function to randomize up our flake attributes
int startY = round(random() % 320);
// set the flake start position
flakeView.center = CGPointMake(490, startY);
flakeView.alpha = 1;
// put the flake in our main view
[self.view addSubview:flakeView];
[UIView animateWithDuration:7
animations:^{
// set the postion where flake will move to
flakeView.center = viewToRotate.center;
}];
Run Code Online (Sandbox Code Playgroud) 我想每隔10秒调用一个方法,但我想使用NSTimer之外的其他方法.我可以用它做什么?
我有一个计数器,counter++每次一个图像接触另一个图像.
现在我想做的是:if counter=2; do something,但我总是得到一个错误:
赋值从整数中生成指针而不进行强制转换
这是代码的一部分:
-(void)checkcollision {
if(CGRectIntersectsRect(flakeImage.frame, viewToRotate.frame)) {
counter++;
}
}
-(void)checknumber {
if(counter=2) {
viewToRotate.alpha=0;
}
}
Run Code Online (Sandbox Code Playgroud) iphone ×4
objective-c ×2
uiimageview ×2
animation ×1
cocoa-touch ×1
counter ×1
height ×1
if-statement ×1
ios ×1
width ×1
xcode ×1