uiscrollviewのサブビュー(uiviews)のタッチの処理の問題
-
13-10-2019 - |
質問
コードを使用してuiscrollviewをクレートし、ビューの配列とuiscrollviewsに追加されたDBから動的に作成しているサブビューを作成しました。 、しかし、コントロールはtouchesbeganになり、touches move methode.eを以下に投稿しました。この問題から克服するのを手伝ってください。
コードを介してscrollviewを作成しましたが、「arrayofviews」という名前の配列にサブビューがあります。これらのサブビューは、配列にあるビューと同じです。通常のビューでDBからのこれらのサブビューを移動できますが、これらのビューをScrollviewに追加していません。
私はネットにある非常に多くのソリューションを試しましたが、適切な解決策を得ることができませんでした。
.mファイル
- (void)viewDidAppear:(BOOL)animated { scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 374)]; scrollview.backgroundColor=[UIColor clearColor]; [scrollview setScrollEnabled:YES]; [scrollview setContentSize:CGSizeMake(300, 600)]; scrollview.showsVerticalScrollIndicator = YES; scrollview.delaysContentTouches=NO; . . . . //here i am retrieving the controls from the DB and adding into the "arrayofviews" array which is an NSMutableArray //I have added subviews in this part to the scroll like [scrollview addSubview:vw1]; [scrollview addSubview:vw2]; . . . scrollview.userInteractionEnabled=NO; scrollview.scrollEnabled=FALSE; [self.view addSubview:scrollview]; [self.view bringSubviewToFront:scrollview]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { scrollview.userInteractionEnabled=YES; [self.nextResponder touchesBegan:touches withEvent:event]; UITouch *touch = [[event allTouches] anyObject]; CGPoint touchLocation; touchLocation.x=scrollview.contentOffset.x; touchLocation.y=scrollview.contentOffset.y; for(UIView *vw in arrayOfViews) { vw.userInteractionEnabled=YES; if([touch view]==vw) { vw.center=touchLocation; } } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event //method to intiate the touch events { [self.nextResponder touchesMoved:touches withEvent:event]; UITouch *touch = [[event touchesForView:scrollview] anyObject]; CGPoint touchLocation1; touchLocation1.x=scrollview.contentOffset.x; touchLocation1.y=scrollview.contentOffset.y; for(UIView *vw in arrayOfViews) { if([touch view]==vw) { vw.center=touchLocation1; //statement to move the control } } }
解決
ラインを変更します
scrollview.userInteractionEnabled = no;
に
scrollview.userInteractionEnabled = yes;
理由
userInteractionEnabledタッチイベントを受け入れるかどうかをデバイスに指示します。 Scrollviewのタッチを無効にしたとき、それがどのように復活したかはイベントに触れています...
乾杯!!!
所属していません StackOverflow