// 手勢(shì)識(shí)別器
// 7 個(gè)子類 : 輕拍手勢(shì) . 平移手勢(shì) . 輕掃手勢(shì) . 縮放手勢(shì) . 旋轉(zhuǎn)手勢(shì) . 長(zhǎng)按手勢(shì) . 以及 屏幕邊界平移手勢(shì)
// 1. 輕拍手勢(shì)
UITapGestureRecognizer*tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
// 往相應(yīng)的控件上添加手勢(shì)
[self.rootV.Imv addGestureRecognizer:tap];
// 連擊次數(shù)
//tap.numberOfTapsRequired = 2;
// 點(diǎn)擊手指數(shù)
//tap.numberOfTouchesRequired = 2;
// UIImageView的用戶交互默認(rèn)是關(guān)閉的 需要打開
self.rootV.Imv.userInteractionEnabled=YES;
// 2. 長(zhǎng)按手勢(shì)
UILongPressGestureRecognizer*longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longTapAction:)];
// 設(shè)置最短長(zhǎng)按時(shí)間
longTap.minimumPressDuration= 0.01;
[self.rootV.Imv addGestureRecognizer:longTap];
// 3. 旋轉(zhuǎn)手勢(shì)
UIRotationGestureRecognizer*rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction)];
// [self.rootV.Imv addGestureRecognizer:rotation];
// 4. 捏合手勢(shì)
UIPinchGestureRecognizer*pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[self.rootV.Imv addGestureRecognizer:pinch];
// 5. 平移手勢(shì)
UIPanGestureRecognizer*pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction)];
//[self.rootV.Imv addGestureRecognizer:pan];
// 6. 輕掃手勢(shì)
UISwipeGestureRecognizer*swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction)];
//[self.rootV.Imv addGestureRecognizer:swipe];
// 7. 屏幕邊緣輕掃手勢(shì)
UIScreenEdgePanGestureRecognizer*screenEdge = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenEdgeAction)];
//[self.rootV.Imv addGestureRecognizer:screenEdge];
}
- (void)tapAction:(UITapGestureRecognizer*)sender{
NSLog(@"輕拍手勢(shì)");
UIImageView*temp = (UIImageView*)sender.view;
temp.image= [UIImage imageNamed:@"2"];
}
- (void)longTapAction:(UILongPressGestureRecognizer*)sender{
NSLog(@"長(zhǎng)按手勢(shì)");
if(sender.state==UIGestureRecognizerStateBegan) {
[UIView animateWithDuration:1animations:^{
CGRecttemp = sender.view.frame;
temp.size.width+= 50;
temp.size.height+=50;
sender.view.frame= temp;
}];
}elseif(sender.state==UIGestureRecognizerStateEnded){
[UIView animateWithDuration:1animations:^{
CGRecttemp = sender.view.frame;
temp.size.width-= 50;
temp.size.height-=50;
sender.view.frame= temp;
}];
}
}
- (void)rotationAction{
NSLog(@"旋轉(zhuǎn)手勢(shì)");
}
- (void)pinchAction:(UIPinchGestureRecognizer*)sender{
NSLog(@"捏合手勢(shì)");
sender.view.transform=CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale);
sender.scale= 1;
}
- (void)panAction{
NSLog(@"平移手勢(shì)");
}
- (void)swipeAction{
NSLog(@"輕掃手勢(shì)");
}
- (void)screenEdgeAction{
NSLog(@"屏幕邊緣輕掃手勢(shì)");
}
UIImageView加載動(dòng)圖
// 1. 聲明屬性
@property(nonatomic,retain)UIImageView*Image;
// 2. 初始化
self.Image = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 158, 212)];
self.Image.backgroundColor = [UIColor whiteColor];
[self addSubview:self.Image];
// 3.使用
NSMutableArray *imageArr = [NSMutableArray array];
for (int i = 1; i < 19; i ++) {
NSString *name = [NSString stringWithFormat:@"%d.tiff",i];
[imageArr addObject:[UIImage imageNamed:name]];
}
// 設(shè)置動(dòng)態(tài)圖圖片數(shù)組
self.Image.animationImages = imageArr;
// 設(shè)置播放一次的時(shí)間
self.Image.animationDuration = 0;
// 設(shè)置重復(fù)次數(shù)
self.Image.animationRepeatCount = 0;
// 開始動(dòng)畫
[self.Image startAnimating];
// 結(jié)束動(dòng)畫
//[self.Image stopAnimating];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。