Skip to content

Instantly share code, notes, and snippets.

@thetron
Created October 21, 2011 06:49
Show Gist options
  • Save thetron/1303255 to your computer and use it in GitHub Desktop.
Save thetron/1303255 to your computer and use it in GitHub Desktop.
SGWMScrollView
//
// SGWMScrollView.h
// SmartGardenWateringMobile
//
// Created by Nicholas Bruning on 21/10/11.
// Copyright (c) 2011 Involved. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SGWMScrollView : UIScrollView
@property (nonatomic) CGRect interactiveFrame;
-(id) initWithFrame:(CGRect)frame interactiveFrame:(CGRect)intFrame;
@end
//
// SGWMScrollView.m
// SmartGardenWateringMobile
//
// Created by Nicholas Bruning on 21/10/11.
// Copyright (c) 2011 Involved. All rights reserved.
//
#import "SGWMScrollView.h"
@implementation SGWMScrollView
@synthesize interactiveFrame;
-(id) initWithFrame:(CGRect)frame interactiveFrame:(CGRect)intFrame{
self = [super initWithFrame:frame];
if(self){
self.clipsToBounds = NO;
interactiveFrame = intFrame;
interactiveFrame.origin.x -= frame.origin.x;
interactiveFrame.origin.y -= frame.origin.y;
}
return self;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
CGRect pointTestFrame = interactiveFrame;
pointTestFrame.origin.x += self.contentOffset.x;
pointTestFrame.origin.y += self.contentOffset.y;
if(CGRectContainsPoint(pointTestFrame, point)){
return YES;
}
return NO;
}
@end
CGRect innerFrame = CGRectMake(20, 40, 280, 280);
CGRect outerFrame = CGRectMake(0, 40, 320, 280);
self.scrollView = [[SGWMScrollView alloc] initWithFrame:innerFrame interactiveFrame:outerFrame];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment