为什么我不能排除位于mainView

时间:2016-01-29 13:10:14

标签: ios xcode button uiimage range

如果有人能支持我,我会很高兴。 我想制作一个Point&点击像猴岛一样的冒险。 因此我遇到了问题,希望你能帮我解决。

问题是,我使用的是一个超出主屏幕的UIImage。 当UIImage在mainView中滚动时,无法推送图像。 (图像像按钮一样创建)

这是我的代码:您将在代码中看到我的评论。提前致谢:

- (void)viewDidLoad {

UIView *animaitionView = [[UIView alloc] init];

UIImageView *frame1 = [[UIImageView alloc] initWithFrame:CGRectMake(1600, 60, 40, 40)];// here is the problem, because of the 1600 for position x 
// if I would use a x-position which is much smaller than 1600 which is within of the range of the mainview, then the singleTap_methode would be work. 
// But because of the position which is out of the mobile-display (mainView), the methode does is not working anymore.  
frame1.image = [UIImage imageNamed:@"kreis.png"];
[frame1 setUserInteractionEnabled:YES];


[animaitionView addSubview:frame1];

NSInteger Xspeed = 1;


singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(singleTap_methode)];
singleTap.numberOfTapsRequired = 1;

doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doubleTap_methode)];
doubleTap.numberOfTapsRequired = 2;

[animaitionView addGestureRecognizer:singleTap];
[animaitionView addGestureRecognizer:doubleTap];

[singleTap requireGestureRecognizerToFail:doubleTap];

}

-(void)singleTap_methode{
NSLog(@"singleTap_methode");
}

-(void)doubleTap_methode{
NSLog(@"doubleTap_methode");
}


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

touch = [[event allTouches] anyObject];
touchLocation = [touch locationInView:self.view];
NSUInteger numTaps = [[touches anyObject] tapCount];

[self moveTimer];

}

- (void) moveTo {
animaitionView.frame = CGRectMake(animaitionView.frame.origin.x - Xspeed, 0, [[UIScreen mainScreen] applicationFrame].size.width,
                                      [[UIScreen mainScreen] applicationFrame].size.height);
}

1 个答案:

答案 0 :(得分:0)

我想您忘了将animaitionView添加到mainView

试试这个

[self.View addSubview:animaitionView];

更新示例

 - (void)viewDidLoad {

UIView *animaitionView = [[UIView alloc] init];

UIImageView *frame1 = [[UIImageView alloc] initWithFrame:CGRectMake(1600, 60, 40, 40)]; 
.....

animaitionView.frame = frame1.frame;
[animaitionView addSubview:frame1];
[self.View addSubview:animaitionView];