要縮小通過兩個觸控點的觀點 iOS

2021-09-08 17:39:17 字數 1497 閱讀 3815

#import "mayviewcontroller.h"

#import "touch.h"

@inte***ce mayviewcontroller ()

@end

@implementation mayviewcontroller

- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil

return self;

}- (void)viewdidload

新建乙個檢視類touch,加入在檢視控制器上,在touch.m檔案裡實現縮放功能

#import "touch.h"

@implementation touch

- (id)initwithframe:(cgrect)frame

return self;

}//計算兩點之間的距離

- (cgfloat)distance:(cgpoint)point1 point2:(cgpoint)point2

- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event

//設定觸控點

nsarray *array = [touches allobjects];

uitouch *touch1 = [array firstobject];

uitouch *touch2 = [array lastobject];

//獲取移動前的觸控點

cgpoint firstpreviouspoint = [touch1 previouslocationinview:self];

cgpoint secondpreviouspoint = [touch2 previouslocationinview:self];

//獲取與移動後的觸控點

cgpoint firstcurrentpoint = [touch1 locationinview:self];

cgpoint secondcurrentpoint = [touch2 locationinview:self];

//獲取移動前後的兩點之間的距離

cgfloat previousdistance = [self distance:firstpreviouspoint point2:secondpreviouspoint];

cgfloat currentdistance = [self distance:firstcurrentpoint point2:secondcurrentpoint];

//獲取縮放比例

cgfloat scanl = currentdistance / previousdistance;

//獲得縮放後的檢視大小

self.bounds = cgrectmake(0, 0, self.bounds.size.width * scanl, self.bounds.size.height * scanl);}

是否吞噬觸控點需要控制兩個地方

是否吞噬觸控點需要控制兩個地方 1 ccdirector shareddirector gettouchdispatcher addtargeteddelegate this,kccmenuhandlerpriority 99,true 當上面語句中的第三個引數為false時,該層不會吞噬觸控點,並...

WKWebView的兩個坑點

蘋果在 wkwebview 中的 js runtime 裡事先注入了乙個 window.webkit.messagehandlers.giveuid.postmessage 方法,我們可以使用這個方法直接向 native 層傳值,異常方便。首先,我們要把乙個名為 giveuid 的 scriptme...

c struct的兩個注意點

1.c 的結構體變數在宣告的時候可以省略struct,在c中這樣是不可以的,例子如下 1 include2 include 3using namespace std 45 struct test 910 int main void 11 2.c 的結構體宣告可以宣告在main 函式中,也可以在mai...