I made a sample in which I have sevenswitch inside scrollview and it works fine
- (void)viewDidLoad { [super viewDidLoad]; SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero]; mySwitch.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5); [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; //[self.view addSubview:mySwitch]; mySwitch.on = true; [_cntView addSubview:mySwitch]; SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero]; mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70); [mySwitch3 addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:mySwitch3]; //self.view.backgroundColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f]; mySwitch3.thumbTintColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f]; mySwitch3.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f]; mySwitch3.inactiveColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f]; mySwitch3.onTintColor = [UIColor colorWithRed:0.45f green:0.58f blue:0.67f alpha:1.00f]; mySwitch3.borderColor = [UIColor clearColor]; mySwitch3.shadowColor = [UIColor blackColor]; [_cntView addSubview:mySwitch3]; } - (void)switchChanged:(SevenSwitch *)sender { NSLog(@"Changed value to: %@", sender.on ? @"ON" : @"OFF"); }
In which _cntView is the main view of the container I placed inside scrollview, check if this works for you
Update
As I mentioned in the comment, I didnβt get what you are trying to say with touch tracking, but I did a swipe with a tap gesture that could help
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)]; [scrollview setContentSize:CGSizeMake(self.view.frame.size.width,700)]; [self.view addSubview:scrollview]; SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero]; mySwitch.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5); [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; //[self.view addSubview:mySwitch]; mySwitch.on = true; [scrollview addSubview:mySwitch]; SevenSwitch *mySwitch3 = [[SevenSwitch alloc] initWithFrame:CGRectZero]; mySwitch3.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5 + 70); [mySwitch3 addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; mySwitch3.thumbTintColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f]; mySwitch3.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f]; mySwitch3.inactiveColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f]; mySwitch3.onTintColor = [UIColor colorWithRed:0.45f green:0.58f blue:0.67f alpha:1.00f]; mySwitch3.borderColor = [UIColor clearColor]; mySwitch3.shadowColor = [UIColor blackColor]; [scrollview addSubview:mySwitch3]; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionSingleTap:)]; singleTap.numberOfTapsRequired = 1; singleTap.cancelsTouchesInView = NO; [scrollview addGestureRecognizer:singleTap]; } - (void)actionSingleTap:(UITapGestureRecognizer *)sender { NSLog(@"Tap"); } - (void)switchChanged:(SevenSwitch *)sender { NSLog(@"Changed value to: %@", sender.on ? @"ON" : @"OFF"); }
I made all the new code programmatically, and it detects touch events outside of 7Switch, and also detects touch / tap on seven switches.
If you want to do this scrollview in a Storyboard and change the software scroll using a storyboard
Hardikdg
source share