[Code Note] adds a moving gesture to the background image and a background image gesture.
1. Engineering Drawing.
II ,.
3. Code.
RootViewController. h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UIGestureRecognizerDelegate>@end
RootViewController. m
# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // Add the background image [self addView];} # pragma-mark-functions // background image-(void) addView {// background image in red UIView * parentView = [[UIView alloc] initWithFrame: CGRectMake (50,100,200,200)]; parentView. backgroundColor = [UIColor redColor]; [self. view addSubview: parentView]; [parentView setUserInteractionEnabled: YES]; // movement gesture ** panRcognize = [[Export alloc] initWithTarget: self action: @ selector (handlePan :)]; panRcognize. delegate = self; [panRcognize setEnabled: YES]; [panRcognize finished]; [panRcognize cancelsTouchesInView]; [parentView finished: panRcognize];} # pragma finished Handles-(void) handlePan :( UIPanGestureRecognizer *) recognizer {NSLog (@ "-- Mobile gesture -----") ;}- (void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .}