1

我在动作脚本中有一个页面卷曲代码,我想在我的应用程序中使用该代码,该代码是使用 Xcode(Objective c) 开发的。任何人都可以告诉它是否可能。如果可能的话,请告诉我该怎么做。

动作脚本代码如下

package  
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    import flash.display.GradientType;
    import flash.display.PixelSnapping;
    import flash.display.Sprite;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;

    import asData.clsGlobalConstants;
    import com.DaveLibrary.clsSupport;
    import com.cupcake.Utils;

    public class clsPageTurn extends Sprite 
    {
        private var cMain:clsMain;
        private var gc:clsGlobalConstants;

        private var flipDirection:int;
        private var pageWidth:Number;
        private var pageHeight:Number;
        private var pageWidthHeight:Number;
        private var pivotY:Number;

        private var NextPageLeft:BitmapData;
        private var NextPageRight:BitmapData;

        private var StationaryPage:Sprite;
        private var StationaryPageMask:Sprite;
        private var StationaryPageBitmap:Bitmap;

        private var StationaryShadow:Sprite;
        private var StationaryShadowMask:Sprite;

        private var FlippingPage:Sprite;
        private var FlippingPageBitmap:Bitmap;
        private var FlippingPageMask:Sprite;
        private var FlippingPageBorder:Sprite;

        private var FlippingPageShadow:Sprite;

        private var OutsideShadow:Sprite;
        private var OutsideShadowMask:Sprite;

        private var LeftRect:Rectangle;
        private var RightRect:Rectangle;
        private var LeftPoint:Point;
        private var RightPoint:Point;

        private var StaticLeftRect:Rectangle;
        private var StaticRightRect:Rectangle;
        private var StaticLeftPoint:Point;
        private var StaticRightPoint:Point;

        public var percentage:Number;
        public var useShadows:Boolean = false;

        public function clsPageTurn(Main:clsMain, FlipDirection:int, pWidth:Number = 1366, pHeight:Number = 768, xOffset:Number = -171)
        {
            // constructor code
            cMain = Main;
            gc = cMain.gc;

            this.x = xOffset;

            percentage = 0; // tracks the last percentage that was drawn.

            StationaryPage = new Sprite();
            StationaryPage.x = xOffset;
            this.addChild(StationaryPage);

            StationaryPageBitmap = new Bitmap();
            StationaryPageBitmap.pixelSnapping = PixelSnapping.ALWAYS;
            StationaryPage.addChild(StationaryPageBitmap);

            StationaryPageMask = new Sprite();
            StationaryPageMask.x = xOffset;
            this.addChild(StationaryPageMask);

            useShadows = !clsMain.isSlow;
            if ( useShadows )
            {
                StationaryShadow = new Sprite();
                StationaryShadow.x = xOffset;
                this.addChild(StationaryShadow);

                OutsideShadow = new Sprite();
                OutsideShadow.x = xOffset;
                this.addChild(OutsideShadow);

                OutsideShadowMask = new Sprite();
                OutsideShadowMask.x = xOffset;
                this.addChild(OutsideShadowMask);
            }

            FlippingPage = new Sprite();
            FlippingPage.x = xOffset;
            this.addChild(FlippingPage);

            FlippingPageBitmap = new Bitmap();
            FlippingPageBitmap.pixelSnapping = PixelSnapping.ALWAYS;
            FlippingPage.addChild(FlippingPageBitmap);

            if ( useShadows ) 
            {
                FlippingPageBorder = new Sprite();
                FlippingPage.addChild(FlippingPageBorder);
            }

            FlippingPageMask = new Sprite();
            FlippingPageMask.x = xOffset;
            this.addChild(FlippingPageMask);

            if ( useShadows )
            {
                FlippingPageShadow = new Sprite();
                FlippingPage.addChild(FlippingPageShadow);
            }

            // set the page width and height and other variables for this page flip object.
            pageWidth = pWidth / 2; // the width is the width of one of our half pages, not the full screen width.
            pageHeight = pHeight;
            pageWidthHeight = pageWidth + pageHeight;           
            pivotY = (pageHeight/2) + pageWidth;

            // rect and points for copying the halves.
            LeftRect = new Rectangle(xOffset, 0, pageWidth, pageHeight);
            RightRect = new Rectangle(pageWidth + xOffset, 0, pageWidth, pageHeight);
            LeftPoint = new Point(xOffset,0);
            RightPoint = new Point(pageWidth + xOffset, 0); 

            StaticLeftRect = new Rectangle(0, 0, pageWidth, pageHeight);
            StaticRightRect = new Rectangle(pageWidth, 0, pageWidth, pageHeight);
            StaticLeftPoint = new Point(0,0);
            StaticRightPoint = new Point(pageWidth, 0); 

            flipDirection = FlipDirection;

            // create our page halves.
            NextPageLeft = new BitmapData(pageWidth, pageHeight, true, 0);
            NextPageRight = new BitmapData(pageWidth, pageHeight, true, 0); 

            if(flipDirection > 0) {
                StationaryPageBitmap.bitmapData = NextPageRight;
                FlippingPageBitmap.bitmapData = NextPageLeft;
            } else {
                StationaryPageBitmap.bitmapData = NextPageLeft;
                FlippingPageBitmap.bitmapData = NextPageRight;
            }

            // disable the mouse for this sprite so it doesn't trap events.
            this.mouseEnabled = false;
            this.mouseChildren = false;     
        }

        public function destroy():void
        {
            this.graphics.clear();

            if(this.parent != null) {
                if(this.parent.contains(this)) {
                    this.parent.removeChild(this);
                }
            }

            if(NextPageLeft != null) NextPageLeft.dispose();
            NextPageLeft = null;

            if(NextPageRight != null) NextPageRight.dispose();
            NextPageRight = null;

            if(StationaryPage != null) {
                while(StationaryPage.numChildren < 0) {
                    StationaryPage.removeChildAt(0);
                }
            }
            StationaryPage = null;

            if(StationaryPageMask != null) StationaryPageMask.graphics.clear();
            StationaryPageMask = null;

            if(StationaryShadow != null) StationaryShadow.graphics.clear();
            StationaryShadow = null;

            if(StationaryShadowMask != null) StationaryShadowMask.graphics.clear();
            StationaryShadowMask = null;

            if(OutsideShadow != null) {
                while(OutsideShadow.numChildren < 0) {
                    OutsideShadow.removeChildAt(0);
                }
            }
            OutsideShadow = null;

            if(OutsideShadowMask != null) OutsideShadowMask.graphics.clear();
            OutsideShadowMask = null;

            if(FlippingPage != null) {
                while(FlippingPage.numChildren > 0) {
                    FlippingPage.removeChildAt(0);
                }
            }
            FlippingPage = null;

            if(FlippingPageMask != null) FlippingPageMask.graphics.clear();
            FlippingPageMask = null;

            if(FlippingPageShadow != null) FlippingPageShadow.graphics.clear();
            FlippingPageShadow = null;

            if(FlippingPageBitmap != null) {
                if(FlippingPageBitmap.bitmapData != null) FlippingPageBitmap.bitmapData.dispose();
            }
            FlippingPageBitmap = null;

            gc = null;
            cMain = null;
        }

        public function Initialize( NextPage:BitmapData ):void
        {
            NextPageLeft.copyPixels(NextPage, StaticLeftRect, StaticLeftPoint);
            NextPageRight.copyPixels(NextPage, StaticRightRect, StaticLeftPoint);
            StationaryPageBitmap.smoothing = useShadows;
            FlippingPageBitmap.smoothing = useShadows;

            redraw(0);
        }

        public function InitializeDO( NextPage:DisplayObject ):void
        {
            var rect:Rectangle = NextPage.scrollRect;
            NextPage.scrollRect = LeftRect;
            NextPageLeft.draw( NextPage );
            NextPage.scrollRect = RightRect;
            NextPageRight.draw( NextPage );
            NextPage.scrollRect = rect;
            StationaryPageBitmap.smoothing = useShadows;
            FlippingPageBitmap.smoothing = useShadows;

            redraw(0);
        }


        public function InitializeHelperObjects():void
        {
            var bmData:BitmapData;
            var m:Matrix;
            var colors:Array;
            var alphas:Array;
            var ratios:Array;
            var maxLength:Number = Math.sqrt((pageWidth * pageWidth)+(pageWidthHeight * pageWidthHeight));
            var matrix:Matrix = new Matrix();

            StationaryPageBitmap.x = ((flipDirection * pageWidth) / 2) - (pageWidth / 2);
            StationaryPageBitmap.y = -pivotY - (pageHeight/2);

            StationaryPage.x = pageWidth;
            StationaryPage.y = pivotY + (pageHeight / 2);

            StationaryPageMask.graphics.clear();
            StationaryPageMask.graphics.beginFill(0x00FF00,1);
            StationaryPageMask.graphics.drawRect(((flipDirection > 0) ? 0 : -pageWidth)  , (-pivotY) - (pageWidthHeight / 2), pageWidth, pageWidthHeight);
            StationaryPageMask.graphics.endFill();          
            StationaryPageMask.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));

            colors = [gc.pageTurn_InsideShadow_Color, gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color];
            alphas = [0,0,gc.pageTurn_InsideShadow_Stationary_Max,0,0];
            ratios = [0,85,125,170,255];
            matrix = new Matrix();

            if ( useShadows )
            {
                StationaryShadow.graphics.clear();
                StationaryShadow.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
                StationaryShadow.graphics.drawRect(((flipDirection > 0) ? 0 : -pageWidth), (-pivotY) - (pageWidthHeight / 2), pageWidth, pageWidthHeight);
                StationaryShadow.graphics.endFill();            
                StationaryShadow.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));
            }

            FlippingPageBitmap.x = ((-flipDirection * pageWidth) / 2) - (pageWidth / 2);
            FlippingPageBitmap.y = (-pivotY) - (pageHeight / 2);
            FlippingPage.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));

            maxLength = Math.sqrt((pageWidth * pageWidth)+(pageWidthHeight * pageWidthHeight));
            colors = [gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color,gc.pageTurn_InsideShadow_Color];
            alphas = [0, gc.pageTurn_InsideShadow_Flipping_Max, gc.pageTurn_InsideShadow_Flipping_Max, 0];
            ratios = [0, 100, 150, 255];
            matrix = new Matrix();
            matrix.createGradientBox( pageWidth, FlippingPageBitmap.height, 0, 0, 0);

            if ( useShadows )
            {
                FlippingPageShadow.graphics.clear();
                FlippingPageShadow.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
                FlippingPageShadow.graphics.drawRect(0, 0, FlippingPageBitmap.width, FlippingPageBitmap.height);
                FlippingPageShadow.graphics.endFill();          
                FlippingPageShadow.transform.matrix = new Matrix(1,0,0,1,FlippingPageBitmap.x, FlippingPageBitmap.y);       
            }

            FlippingPageMask.graphics.clear();
            FlippingPageMask.graphics.beginFill(0xFF0000,1);
            FlippingPageMask.graphics.drawRect(((-flipDirection * pageWidthHeight) / 2) - (pageWidthHeight/2), (-pivotY) - (pageWidthHeight / 2), pageWidthHeight, pageWidthHeight*2);
            FlippingPageMask.graphics.endFill();
            FlippingPageMask.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));

            if ( useShadows )
            {
                OutsideShadow.graphics.clear();
                OutsideShadow.graphics.beginFill(0x000000,cMain.gc.pageTurn_OutsideShadow_Alpha);
                OutsideShadow.graphics.drawRect(FlippingPageBitmap.x, FlippingPageBitmap.y, FlippingPageBitmap.width, FlippingPageBitmap.height);
                OutsideShadow.graphics.endFill();
                OutsideShadow.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));

                OutsideShadowMask.graphics.clear();
                OutsideShadowMask.graphics.beginFill(0x0000FF,1);
                OutsideShadowMask.graphics.drawRect(((-flipDirection * pageWidthHeight) / 2) - (pageWidthHeight/2), (-pivotY) - (pageWidthHeight / 2), pageWidthHeight, pageWidthHeight*2);
                OutsideShadowMask.graphics.endFill();
                OutsideShadowMask.transform.matrix = new Matrix(1,0,0,1,pageWidth, pivotY + (pageHeight / 2));

                FlippingPageBorder.x = FlippingPageBitmap.x;
                FlippingPageBorder.y = FlippingPageBitmap.y;
                FlippingPageBorder.width = pageWidth;
                FlippingPageBorder.height = pageHeight;

                FlippingPageBorder.graphics.clear();
                FlippingPageBorder.graphics.beginFill(0x000001, 1);
                FlippingPageBorder.graphics.drawRect(0,0,gc.pageTurn_Border_Size, pageHeight);
                FlippingPageBorder.graphics.endFill();
                FlippingPageBorder.graphics.beginFill(0x000001, 1);
                FlippingPageBorder.graphics.drawRect(gc.pageTurn_Border_Size,0,pageWidth-(gc.pageTurn_Border_Size*2), gc.pageTurn_Border_Size);
                FlippingPageBorder.graphics.endFill();
                FlippingPageBorder.graphics.beginFill(0x000001, 1);
                FlippingPageBorder.graphics.drawRect(gc.pageTurn_Border_Size,pageHeight - gc.pageTurn_Border_Size,pageWidth - (gc.pageTurn_Border_Size*2), gc.pageTurn_Border_Size);
                FlippingPageBorder.graphics.endFill();
                FlippingPageBorder.graphics.beginFill(0x000001, 1);
                FlippingPageBorder.graphics.drawRect(pageWidth - gc.pageTurn_Border_Size,0,gc.pageTurn_Border_Size, pageHeight);
                FlippingPageBorder.graphics.endFill();
                FlippingPageBorder.visible = true;
            }

            StationaryPage.mask = StationaryPageMask;
            FlippingPage.mask = FlippingPageMask;
            if ( useShadows ) OutsideShadow.mask = OutsideShadowMask;
        }

        public function redraw(Percentage:Number):void
        {
            percentage = Utils.Clamp( Percentage, 0, 1 );

            var rot:Number = flipDirection * 45 * Percentage;

            rotateSprite(FlippingPage, (flipDirection * 90) - rot * 2);

            if ( useShadows )
            {
                FlippingPageShadow.alpha = 0;
                StationaryShadow.alpha = clsSupport.GetBezier2DPercentage(0,0,1,1,Percentage);
                FlippingPageBorder.alpha =  gc.pageTurn_Border_Alpha * (1 - percentage);
                rotateSprite(OutsideShadow, ((flipDirection * 90) - rot * 2) + (clsSupport.GetBezier2DPercentage(gc.pageTurn_OutsideShadow_OffsetStart, gc.pageTurn_OutsideShadow_OffsetEnd, gc.pageTurn_OutsideShadow_LeadIn, gc.pageTurn_OutsideShadow_LeadOut, Percentage) * -flipDirection));
                rotateSprite(StationaryShadow, (flipDirection * 45) - rot );
                rotateSprite(OutsideShadowMask, (flipDirection * 45) - rot);
            }

            rotateSprite(StationaryPageMask, (flipDirection * 45) - rot );          
            rotateSprite(FlippingPageMask, (flipDirection * 45) - rot);

            if(Percentage == 0 && useShadows) 
            {
                FlippingPageBorder.x = FlippingPageBitmap.x;
                FlippingPageBorder.y = FlippingPageBitmap.y;
                FlippingPageBorder.width = FlippingPageBitmap.bitmapData.width;
                FlippingPageBorder.height = FlippingPageBitmap.bitmapData.height;
            }
        }

        private function rotateSprite(spr:Sprite, degress:Number):void
        {
            var m:Matrix;
            var x:Number;
            var y:Number;
            x = spr.x;
            y = spr.y;
            m = spr.transform.matrix;
            m.a = 1;
            m.b = 0;
            m.c = 0;
            m.d = 1;
            m.rotate(clsSupport.ToRadians(degress));
            m.tx = x;
            m.ty = y;
            spr.transform.matrix = m;
        }
    }
}

谁能告诉我如何做到这一点。任何帮助将不胜感激。

4

2 回答 2

0

不可能的。如果要在objective-c中使用,必须直接移植。请注意,页面卷曲效果是内置在 iOS 中的。使用 iPhone 上的代码使用 Air 进行 iOS 开发。

于 2013-02-12T04:51:32.640 回答
0

使用 UIPageViewController 来获得这种卷曲效果。将 transitionStyle 设置为UIPageViewControllerTransitionStylePageCurl或使用 init-method – initWithTransitionStyle:navigationOrientation:options:。创建您想要使用的所有 viewController 的实例,将它们放入一个数组中。这个数组是setViewControllers:direction:animated:completion:方法的第一个参数。

于 2013-02-12T07:37:12.187 回答