Graphics Reference
In-Depth Information
implement any other iOS-specific behavior such as scroll bouncing (when a view
elastically snaps back into place after scrolling past its bounds).
Let's use a CAScrollLayer to create a very basic UIScrollView replacement. We'll
create a custom UIView that uses a CAScrollLayer as its backing layer, and then use
UIPanGestureRecognizer to implement the touch handling. The code is shown in
Listing 6.10. Figure 6.11 shows the ScrollView being used to pan around a
UIImageView that is larger than the ScrollView frame.
Listing 6.10 Implementing a Scrolling View Using CAScrollLayer
#import "ScrollView.h"
#import <QuartzCore/QuartzCore.h>
@implementation ScrollView
+ ( Class )layerClass
{
return [ CAScrollLayer class ];
}
- ( void )setUp
{
//enable clipping
self . layer . masksToBounds = YES ;
//attach pan gesture recognizer
UIPanGestureRecognizer *recognizer = nil ;
recognizer = [[ UIPanGestureRecognizer alloc ]
initWithTarget : self action : @selector (pan:)];
[ self addGestureRecognizer :recognizer];
}
- ( id )initWithFrame:( CGRect )frame
{
//this is called when view is created in code
if (( self = [ super initWithFrame :frame]))
{
[ self setUp ];
}
return self ;
}
- ( void )awakeFromNib
{
//thi s is called when view is created from a nib
Search WWH ::




Custom Search