Skip to content

Instantly share code, notes, and snippets.

@j4johnfox
Created March 25, 2010 02:46
Show Gist options
  • Save j4johnfox/343103 to your computer and use it in GitHub Desktop.
Save j4johnfox/343103 to your computer and use it in GitHub Desktop.
- (void)setAnchorPoint:(CGPoint)anAnchorPoint
inPhotoLayer:(CALayer)aPhotoLayer
{
log('anAnchorPoint is ' +CPStringFromPoint(anAnchorPoint));
if (aPhotoLayer._DOMContentsElement == null)
{
log('aPhotoLayer has no _DOMContentsElement cannot set its anchor point, bail');
return;
}
var styleObject = aPhotoLayer._DOMContentsElement.style;
var xVal = (anAnchorPoint.x * 100 +'%');
var yVal = (anAnchorPoint.y * 100 +'%');
log('xVal is ' +xVal +' yVal is ' +yVal);
if (CPBrowserIsEngine(CPWebKitBrowserEngine) && (typeof styleObject.WebkitTransformOrigin != "undefined"))
{
styleObject.WebkitTransformOrigin = +xVal +" " +yVal;
[aPhotoLayer setNeedsDisplay];
}
else if (CPBrowserIsEngine(CPGeckoBrowserEngine) && (typeof styleObject.MozTransformOrigin != "undefined"))
{
styleObject.MozTransformOrigin = +xVal +" " +yVal;
[aPhotoLayer setNeedsDisplay];
}
/*
else if (CPBrowserIsEngine(CPOperaBrowserEngine))
{
//transformName = '-o-transform';
}
*/
else
{
[aPhotoLayer setAnchorPoint:anAnchorPoint];
}
}
- (void)zoomPhotoLayer:(CALayer)aPhotoLayer
byScaleFactor:(CGFloat)aScaleFactor
{
var myTransformAnimation;
//see: http://maettig.com/code/css/css-transform.html
log('aPhotoLayer._DOMContentsElement is ' +aPhotoLayer._DOMContentsElement);
if (aPhotoLayer._DOMContentsElement == null)
{
log('aPhotoLayer has no _DOMContentsElement, bail');
return;
}
var styleObject = aPhotoLayer._DOMContentsElement.style;
log('aPhotoLayer is ' +aPhotoLayer +' styleObject is ' +styleObject +' [imageView imageLayer]._DOMContentsElement is '
+[imageView imageLayer]._DOMContentsElement);
if (CPBrowserIsEngine(CPWebKitBrowserEngine) && (typeof styleObject.WebkitTransform != "undefined"))
{
styleObject.WebkitTransform = "scale(" + aScaleFactor + ")";
[aPhotoLayer setNeedsDisplay];
}
else if (CPBrowserIsEngine(CPGeckoBrowserEngine) && (typeof styleObject.MozTransform != "undefined"))
{
styleObject.MozTransform = "scale(" + aScaleFactor + ")";
[aPhotoLayer setNeedsDisplay];
}
/*
else if (CPBrowserIsEngine(CPOperaBrowserEngine))
{
//transformName = '-o-transform';
}
*/
else
{
var myTransform = CGAffineTransformMakeScale(aScaleFactor, aScaleFactor);
[aPhotoLayer setAffineTransform:myTransform];
[aPhotoLayer setNeedsDisplay];
}
/*
var myTransform = CGAffineTransformMakeScale(aScaleFactor, aScaleFactor);
[aPhotoLayer setAffineTransform:myTransform];
[aPhotoLayer setNeedsDisplay];
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment