Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Monotouch ipad内存/动画问题_C#_Ipad_Memory_Animation_Xamarin.ios - Fatal编程技术网

C# Monotouch ipad内存/动画问题

C# Monotouch ipad内存/动画问题,c#,ipad,memory,animation,xamarin.ios,C#,Ipad,Memory,Animation,Xamarin.ios,总之,我正在开发一个我认为相当简单的应用程序。我在一个视图中使用多个视图控制器,该视图下有按钮和单个图像视图。buttonpress事件触发要显示的其他viewcontroller视图。那很好用。但是,我还想设置过渡动画以模拟翻页。我使用下面的代码来实现这一点。它工作得很好,但是,每次我使用这个方法,使用的内存都会增加。使用的内存似乎与图像阵列的实际大小断开连接。另外,我从png改为jpeg(小得多的图像),它没有什么区别。我考虑过使用.mov,但加载时间非常明显 请帮忙。我尝试了很多不同的方法

总之,我正在开发一个我认为相当简单的应用程序。我在一个视图中使用多个视图控制器,该视图下有按钮和单个图像视图。buttonpress事件触发要显示的其他viewcontroller视图。那很好用。但是,我还想设置过渡动画以模拟翻页。我使用下面的代码来实现这一点。它工作得很好,但是,每次我使用这个方法,使用的内存都会增加。使用的内存似乎与图像阵列的实际大小断开连接。另外,我从png改为jpeg(小得多的图像),它没有什么区别。我考虑过使用.mov,但加载时间非常明显

请帮忙。我尝试了很多不同的方法来强制垃圾收集。我翻阅了有限的文本,搜索了这个网站,但没有结果

下面是一个代码示例

公共部分类AppDelegate:UIApplicationDelegate {

//当应用程序加载其UI并准备运行时,将调用此方法
公共覆盖bool FinishedLaunching(UIApplication应用程序、NSDictionary选项)
{
UIApplication.SharedApplication.SetStatusBarHidden(true,true);
//如果已定义视图,请将其添加到此处:
//window.AddSubview(navigationController.View);
//window.AddSubview(mainController.View);
window.MakeKeyAndVisible();
coverOpenbtn.TouchUpInside+=手柄CoverOpenBtnTouchInside;
backBtn1.TouchUpInside+=车把靠背btn1touchupInside;
返回true;
}
无效HandleBackBtn1TouchUpInside(对象发送器,事件参数e)
{
this.navView.RemoveFromSuperview();
List myImages=新列表();
添加(UIImage.FromFile(“c_1_00011.jpg”);
添加(UIImage.FromFile(“c_1_00010.jpg”);
添加(UIImage.FromFile(“c_1_00009.jpg”);
添加(UIImage.FromFile(“c_1_00008.jpg”);
添加(UIImage.FromFile(“c_1_00007.jpg”);
添加(UIImage.FromFile(“c_1_00006.jpg”);
添加(UIImage.FromFile(“c_1_00005.jpg”);
添加(UIImage.FromFile(“c_1_00004.jpg”);
添加(UIImage.FromFile(“c_1_00003.jpg”);
添加(UIImage.FromFile(“c_1_00002.jpg”);
添加(UIImage.FromFile(“c_1_00001.jpg”);
添加(UIImage.FromFile(“c_1_00000.jpg”);
//添加(UIImage.FromFile(“c_1_00012.jpg”);
var myAnimatedView=newUIImageView(window.Bounds);
myAnimatedView.AnimationImages=myImages.ToArray();
myAnimatedView.AnimationDuration=1;//秒
myAnimatedView.AnimationRepeatCount=1;
myAnimatedView.StartAnimating();
添加子视图(myAnimatedView);
}
void HandleCoverOpenbtnTouchUpInside(对象发送方,事件参数e)
{
this.coverView.AddSubview(navView);
List myImages=新列表();
添加(UIImage.FromFile(“c_1_00000.jpg”);
添加(UIImage.FromFile(“c_1_00001.jpg”);
添加(UIImage.FromFile(“c_1_00002.jpg”);
添加(UIImage.FromFile(“c_1_00003.jpg”);
添加(UIImage.FromFile(“c_1_00004.jpg”);
添加(UIImage.FromFile(“c_1_00005.jpg”);
添加(UIImage.FromFile(“c_1_00006.jpg”);
添加(UIImage.FromFile(“c_1_00007.jpg”);
添加(UIImage.FromFile(“c_1_00008.jpg”);
添加(UIImage.FromFile(“c_1_00009.jpg”);
添加(UIImage.FromFile(“c_1_00010.jpg”);
添加(UIImage.FromFile(“c_1_00011.jpg”);
//添加(UIImage.FromFile(“c_1_00012.jpg”);
var myAnimatedView=newUIImageView(window.Bounds);
myAnimatedView.AnimationImages=myImages.ToArray();
myAnimatedView.AnimationDuration=1;//秒
myAnimatedView.AnimationRepeatCount=1;
开放++;
}
myAnimatedView.StartAnimating();
添加子视图(myAnimatedView);
}
这里有一些提示(只需阅读代码):

  • 一旦图像加载到内存中,JPEG和PNG之间就没有区别了。格式仅在存储图像而不是显示图像时起作用。一旦加载(和解压缩),它们将占用略多于(宽度*高度*位数)的内存

  • 考虑缓存您的图像并仅在它们不可用时加载它们。GC将决定何时收集它们(因此可能同时存在多个副本)。现在,当您可以加载一次图像时,您将加载每个图像两次(并使用单独的数组对它们进行排序)

  • 即使您缓存它们,也要随时准备按需清除它们,例如,如果iOS警告您内存不足。覆盖ReceiveMemoryWarning以清除列表(或更好的数组)

  • 如果可以避免,不要调用ToArray(如示例代码)。如果知道有多少图像,只需创建大小合适的数组(并缓存两个数组;-)。它将减少(一点)拨款

  • >P>甚至考虑缓存“My动画视图”UIVIEVIEW(如果上面没有足够帮助)

  • 帮助别人,一个接一个地尝试,告诉我们什么对你最有帮助:-)

图像用于“动画化”翻页…这是用于在应用程序中导航吗

例如,你从“主页”开始,按下一个按钮,然后它会为你的应用程序中的下一个屏幕设置翻页动画


我认为你最好考虑使用CoreGraphics来尝试实现这种效果,这两种方法在内存方面都会更有效率,而且可能看起来也会更好。Objective-C中有几个项目可以帮助您开始,例如

好的,这是我找到的最好的解决方案,不会使硬件崩溃,并且通常对其他任务有用

这是进入按钮按下处理程序的代码,每个NavI
    // This method is invoked when the application has loaded its UI and its ready to run
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        UIApplication.SharedApplication.SetStatusBarHidden( true, true);
        // If you have defined a view, add it here:
        // window.AddSubview (navigationController.View);
        //window.AddSubview(mainController.View);
        window.MakeKeyAndVisible ();

        coverOpenbtn.TouchUpInside += HandleCoverOpenbtnTouchUpInside;
        backBtn1.TouchUpInside += HandleBackBtn1TouchUpInside;
        return true;
    }

    void HandleBackBtn1TouchUpInside (object sender, EventArgs e)
    {
        this.navView.RemoveFromSuperview();

        List<UIImage> myImages = new List<UIImage>();

        myImages.Add(UIImage.FromFile("c_1_00011.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00010.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00009.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00008.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00007.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00006.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00005.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00004.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00003.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00002.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00001.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00000.jpg"));
        //myImages.Add(UIImage.FromFile("c_1_00012.jpg"));
        var myAnimatedView = new UIImageView(window.Bounds);
        myAnimatedView.AnimationImages = myImages.ToArray();
        myAnimatedView.AnimationDuration = 1; // Seconds
        myAnimatedView.AnimationRepeatCount = 1; 
        myAnimatedView.StartAnimating();
        window.AddSubview(myAnimatedView);

    }

    void HandleCoverOpenbtnTouchUpInside (object sender, EventArgs e)
    {
        this.coverView.AddSubview(navView);

        List<UIImage> myImages = new List<UIImage>();

        myImages.Add(UIImage.FromFile("c_1_00000.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00001.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00002.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00003.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00004.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00005.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00006.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00007.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00008.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00009.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00010.jpg"));
        myImages.Add(UIImage.FromFile("c_1_00011.jpg"));
        //myImages.Add(UIImage.FromFile("c_1_00012.jpg"));
        var myAnimatedView = new UIImageView(window.Bounds);
        myAnimatedView.AnimationImages = myImages.ToArray();
        myAnimatedView.AnimationDuration = 1; // Seconds
        myAnimatedView.AnimationRepeatCount = 1; 
            opened++;
        }
        myAnimatedView.StartAnimating();
        window.AddSubview(myAnimatedView);
    }
NSTimer.CreateScheduledTimer(.1,delegate { navImage1.Alpha = 1;     NSTimer.CreateScheduledTimer(.1,delegate { navImage2.Alpha = 1; 
            NSTimer.CreateScheduledTimer(.05,delegate { navImage3.Alpha = 1; 
                    NSTimer.CreateScheduledTimer(.05,delegate { navImage4.Alpha = 1;
                    NSTimer.CreateScheduledTimer(.05,delegate { navImage5.Alpha = 1;
                        NSTimer.CreateScheduledTimer(.05,delegate { navImage6.Alpha = 1;
                            NSTimer.CreateScheduledTimer(.05,delegate { navImage7.Alpha = 1;
                                NSTimer.CreateScheduledTimer(.05,delegate { navImage8.Alpha = 1;
                                    NSTimer.CreateScheduledTimer(.05,delegate { navImage9.Alpha = 1;
                                        NSTimer.CreateScheduledTimer(.05,delegate { navImage.Alpha = 1; });});});});});});});});});});