Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android程序開發之給背景圖加上移動的手勢

Android程序開發之給背景圖加上移動的手勢

編輯:關於Android編程

一,工程圖。


二,效果圖。


三,代碼。

RootViewController.h

#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
<UIGestureRecognizerDelegate>
@end 

RootViewController.m

#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//增加背景圖
[self addView];
}
#pragma -mark -functions
//背景圖
-(void)addView
{
//紅色的背景圖
UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
parentView.backgroundColor=[UIColor redColor];
[self.view addSubview:parentView];
[parentView setUserInteractionEnabled:YES];
//移動的手勢
UIPanGestureRecognizer *panRcognize=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
panRcognize.delegate=self;
[panRcognize setEnabled:YES];
[panRcognize delaysTouchesEnded];
[panRcognize cancelsTouchesInView];
[parentView addGestureRecognizer:panRcognize];
}
#pragma UIGestureRecognizer Handles
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
NSLog(@"--移動的手勢-----");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

以上代碼是有關Android程序開發之給背景圖加上移動的手勢的全部內容,希望對大家有所幫助!

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved