Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2011, 12:55 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Location: Coimbatore,TamilNadu
Posts: 2
Sankar Chandra Bose is on a distinguished road
Default Issues in handling touches on subviews(uiviews) in UIScrollView

I have created a UIScrollView using code and i have created subviews which i am creating dynamically from the DB that are added to the array of views and to the UIScrollviews.I am using touchesBegan and touchesMoved methods.The sub view which i am selecting is not recognized,but the control comes into touchesBegan and touches moved method.I have posted the code below.Please anybody help me to overcome from this issue.

I have created the scrollview through code and i have subviews in an array named "arrayofviews".these subviews are the same views which are in the array.I am able to move these subviews which are from the DB on a normal view,but when i added these views to the scrollview its not working.

I have tried so many solutions which are in the net,but i couldn't get a proper solution.

.m file
Code:
- (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
  }
 }

}
Please somebody help me...Please say me where i am wrong..Please...Please
Sankar Chandra Bose is offline   Reply With Quote
Reply

Bookmarks

Tags
touches, touchesbegan, uiscrollview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 356
10 members and 346 guests
7twenty7, dre, iAppDeveloper, jeroenkeij, Mah6447, Morrisone, sacha1996, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0