scott,
I followed your suggestions, but the touchesBegan, touchesEnded etc. is still unable to receive anything. Here's the code:
Code:
#import "PageScrollView.h"
@implementation PageScrollView
-(id)initWithFrame:(CGRect)frame : (int)showPage {
self = [ super initWithFrame: frame ];
if (self != nil) {
_pages = nil;
_pageRegion = CGRectMake(0.0, 0.0, 320.0,420.0);
_controlRegion = CGRectMake(0.0, 420.0,320.0, 0.0);
self.delegate = nil;
scrollView = [ [ UIScrollView alloc ] initWithFrame: _pageRegion ];
scrollView.pagingEnabled = YES;
scrollView.clipsToBounds = YES;
scrollView.userInteractionEnabled = YES;
scrollView.scrollEnabled = YES;
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
scrollView.directionalLockEnabled = YES;
scrollView.delegate = self;
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 5.0;
[ self addSubview: scrollView ];
pageControl = [ [ UIPageControl alloc ] initWithFrame: _controlRegion ];
[ pageControl addTarget: self action: @selector(pageControlDidChange:)
forControlEvents: UIControlEventValueChanged ];
[ self addSubview: pageControl ];
[ scrollView setContentOffset:
CGPointMake(_pageRegion.size.width * showPage, scrollView.contentOffset.y)
animated: YES
];
pageControl.currentPage = showPage;
} else {
pageControl.currentPage = showPage;
}
return self;
}
-(void)myPage:(int) myPage {
NSLog(@"MY PAGE: %d", myPage);
}
-(void)setPages:(NSMutableArray *)pages {
if (_pages != nil) {
for(int i=0;i<[_pages count];i++) {
[ [ _pages objectAtIndex: i ] removeFromSuperview ];
}
}
_pages = pages;
scrollView.contentOffset = CGPointMake(0.0, 0.0);
scrollView.contentSize = CGSizeMake(_pageRegion.size.width * [ _pages count ], 0.0);
scrollView.backgroundColor = [UIColor darkGrayColor];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
pageControl.numberOfPages = [ _pages count ];
pageControl.currentPage = 0;
[ self layoutViews ];
}
- (void)layoutViews {
for(int i=0;i<[ _pages count];i++) {
UIView *page = [ _pages objectAtIndex: i ];
page.backgroundColor = [UIColor darkGrayColor];
CGRect bounds = page.bounds;
CGRect frame = CGRectMake(_pageRegion.size.width * i, 0.0,
320,400);
page.frame = frame;
page.bounds = bounds;
[ scrollView addSubview: page ];
}
}
-(id)getDelegate {
return _delegate;
}
- (void)setDelegate:(id)delegate {
_delegate = delegate;
}
-(NSMutableArray *)getPages {
return _pages;
}
-(void)setCurrentPage:(int)page {
[ scrollView setContentOffset:
CGPointMake(_pageRegion.size.width * page, scrollView.contentOffset.y)
animated: YES
];
pageControl.currentPage = page;
}
-(int)getCurrentPage {
return (int) (scrollView.contentOffset.x / _pageRegion.size.width);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControl.currentPage = self.currentPage;
[ self notifyPageChange ];
}
-(void) pageControlDidChange: (id)sender
{
UIPageControl *control = (UIPageControl *) sender;
if (control == pageControl) {
self.currentPage = control.currentPage;
}
[ self notifyPageChange ];
}
-(void) notifyPageChange {
if (self.delegate != nil) {
if ([ _delegate conformsToProtocol:@protocol(PageScrollViewDelegate) ]) {
if ([ _delegate respondsToSelector:
@selector(pageScrollViewDidChangeCurrentPage:currentPage:) ])
{
[ self.delegate pageScrollViewDidChangeCurrentPage:
(PageScrollView *)self currentPage: self.currentPage
];
}
}
}
}
-(BOOL)touchesShouldCancelInContentView:(UIView *) view {
return YES;
}
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
return NO;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch moved");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = YES;
NSLog(@"touch begin");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touch end");
}
/*
http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/
*/
-(void)myNavControllerHide {
[[self.delegate navigationController] setNavigationBarHidden:YES animated:YES];
}
@end
Kindly let me know where I am going wrong..... Thanks