objc避免动态绑定,提高速度.(2009-09-28 10:02)
|
void (*setter)(id, SEL, BOOL);
|
int i;
|
|
setter = (void (*)(id, SEL, BOOL))[target
|
methodForSelector:@selector(setFilled:)];
|
for ( i = 0; i < 1000, i++ )
|
setter(targetList[i], @selector(setFilled:), YES);
|
#pragma mark -- mask image's gesture --
#define DRAG_MIN 8
- (UIView*)webDocumentView
{
NSArray *array = [[[webView subviews]
objectAtIndex:0] subviews];
for(UIView *v in array)
{
if([v
respondsToSelector:@selector(loadRequest:)])
return
v;
}
return nil;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent
*)event
{
if([touches count] > 1)
{
touchA = [[touches
allObjects] objectAtIndex:0];
touchB = [[touches
allObjects] objectAtIndex:1];
}
else
{
if(!touchA)
touchA =
[[touches allObjects] objectAtIndex:0];
else
touchB =
[[touches allObjects] objectAtIndex:0];
}
if(!touchB)
[[self webDocumentView]
touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent
*)event
{
if(touchA && touchB)
{
CGPoint prevA = [touchA
previousLocationInView:maskView];
CGPoint currA = [touchA
locationInView:maskView];
CGPoint prevB = [touchB
previousLocationInView:maskView];
CGPoint currB = [touchB
locationInView:maskView];
int lvl = [[webView
stringByEvaluatingJavaScriptFromString:@'map.getZoom()']
intValue];
NSString *errMsg = nil;
if(fabs(currB.x - currA.x) +
fabs(currB.y - currA.y) > fabs(prevB.x - prevA.x) + fabs(prevB.y
- prevA.y))
{
[webView
stringByEvaluatingJavaScriptFromString:@'map.zoomIn();'];
if([[webView
stringByEvaluatingJavaScriptFromString:@'map.getZoom()'] intValue]
== lvl)
errMsg = @'can no longer zoom in';
}
else
{
[webView
stringByEvaluatingJavaScriptFromString:@'map.zoomOut();'];
if([[webView
stringByEvaluatingJavaScriptFromString:@'map.getZoom()'] intValue]
== lvl)
errMsg = @'can no longer zoom out';
}