主要重寫了4個方法:
- (void)touchesbegan:(nsset*)touches withevent:(uievent*)event
- (void)touchesmoved:(nsset*)touches withevent:(uievent*)event
- (void)touchesended:(nsset*)touches withevent:(uievent*)event
- (void)touchescancelled:(nsset*)touches withevent:(uievent*)event
主要**如下,原理見注釋:
@protocol cayswirlgesturerecognizerdelegate @end
@inte***ce cayswirlgesturerecognizer : uigesturerecognizer
@property cgfloat currentangle;
@property cgfloat previousangle;
@end
#import "cayswirlgesturerecognizer.h"
@inte***ce cayswirlgesturerecognizer ()
@property (strong, nonatomic) id target;
@property (nonatomic) sel action;
@end
@implementation cayswirlgesturerecognizer
- (id)initwithtarget:(id)target action:(sel)action
return self;
}- (void)touchesbegan:(nsset*)touches withevent:(uievent *)event
}- (void)touchesmoved:(nsset*)touches withevent:(uievent *)event
}- (void)touchesended:(nsset*)touches withevent:(uievent *)event
- (void)touchescancelled:(nsset*)touches withevent:(uievent *)event
- (float)gettouchangle:(cgpoint)touch
else
}float arctan = atanf(x/y);
// figure out which quadrant we're in
// quadrant i 第一象限
if ((x >= 0) && (y > 0))
// quadrant ii 第二象限
else if ((x < 0) && (y > 0))
// quadrant iii
else if ((x <= 0) && (y < 0))
// quadrant iv
else if ((x > 0) && (y < 0))
return -1;
}@end
在view上新增手勢:
self.swirlgesturerecognizer = [[cayswirlgesturerecognizer alloc] initwithtarget:self action:@selector(rotationaction:)];
[self.swirlgesturerecognizer setdelegate:self];
[self.controlsview addgesturerecognizer:self.swirlgesturerecognizer];
action方法主要是做變換旋**
- (void)rotationaction:(id)sender
cgfloat direction = ((cayswirlgesturerecognizer*)sender).currentangle - ((cayswirlgesturerecognizer*)sender).previousangle;
bearing += 180 * direction / m_pi;
if (bearing < -0.5)
else if (bearing > 359.5)
cgaffinetransform knobtransform = self.knob.transform;
cgaffinetransform newknobtransform = cgaffinetransformrotate(knobtransform, direction);
[self.knob settransform:newknobtransform];
self.position.text = [nsstring stringwithformat:@"%dº", (int)lroundf(bearing)];
}
最終的效果如下:
建立自定義控制項
在前一篇文章中 中,我將乙個公共視窗控制項進行了之類劃分,目的是為了修飾其行為或者說是擴充套件其功能。有時候,你只能將公共視窗控制項擴充套件到這樣的底部。我遇到的乙個例子是乙個比較普遍的話題即需要乙個格網控制項並且編輯tabular資料。我對clistctrl進行了之類劃分,並擴充套件使其能夠進行子...
建立自定義物件
你並不侷限於前幾節所討論的jscript的內建物件,你可以自定義包含有你自己的方法和屬性的物件來擴充jscript,這是jscript的乙個強大的特性。例如,你可以建立乙個名為webuser的物件,它包含參觀你網點的使用者的資訊,這個物件可以包含諸如使用者名稱 密碼和註冊狀態之類的屬性,將所有這些屬...
建立自定義選單
直接用類呼叫建立選單方法即可 整個思路步驟 1.呼叫介面獲取access token 2.準備json資料,需要傳過去的選單 3.採用 access token 介面進行建立即可 如下 進行自定義新增選單 第乙個步驟 獲取token ch curl init curl setopt ch,curlo...