gpt4 book ai didi

ios - 当图像移动时,如何按住并拖动图像?

转载 作者:行者123 更新时间:2023-11-29 03:33:45 25 4
gpt4 key购买 nike

这是我随机移动图像和触摸代码的代码。

-(void)viewDidAppear:(BOOL)animated {

timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(randomizeXandY) userInfo:nil repeats:YES];
}

-(void)randomizeXandY {

CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) self.view.bounds.size.height);

[self moveObjectsAtX:x Y:y];

}

-(void)moveObjectsAtX:(CGFloat)x Y:(CGFloat)y {

[UIView animateWithDuration:5 animations:^{
imgView.center = CGPointMake(x, y);
}];

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches]anyObject];
CGPoint touchLocation = [touch locationInView:self.view];

if ([touch view] == imgView) {

imgView.center = touchLocation;
}

}

最佳答案

试试touchesBegin和touchesEnded中的代码

-(void)touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event {

// stop timers here

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

// start timers here again

}

关于ios - 当图像移动时,如何按住并拖动图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19445396/

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