Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
Objective c 如何在屏幕外设置ui视图动画,并在应用程序启动时保持不变&;不是每次加载视图时都这样吗?_Objective C_Ios_Core Animation - Fatal编程技术网

Objective c 如何在屏幕外设置ui视图动画,并在应用程序启动时保持不变&;不是每次加载视图时都这样吗?

Objective c 如何在屏幕外设置ui视图动画,并在应用程序启动时保持不变&;不是每次加载视图时都这样吗?,objective-c,ios,core-animation,Objective C,Ios,Core Animation,我在应用程序的开头有一个简单的动画 它在主视图上显示UIView,在启动时在屏幕外设置动画。我只希望它在应用程序启动时动画,而不是每次加载主视图时。我的问题是,使用“我的代码”可以根据需要停止动画,但在加载主视图时,动画会恢复到覆盖视图的开始状态 总而言之,我想在屏幕外设置UIview的动画,并使其保持在屏幕上,直到重新启动应用程序。非常感谢您的任何建议 - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addO

我在应用程序的开头有一个简单的动画

它在主视图上显示UIView,在启动时在屏幕外设置动画。我只希望它在应用程序启动时动画,而不是每次加载主视图时。我的问题是,使用“我的代码”可以根据需要停止动画,但在加载主视图时,动画会恢复到覆盖视图的开始状态

总而言之,我想在屏幕外设置UIview的动画,并使其保持在屏幕上,直到重新启动应用程序。非常感谢您的任何建议

- (void)viewDidLoad
{



    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performAnimation:) name:UIApplicationDidBecomeActiveNotification   object:nil];




[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

 }

 - (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];

[self setDoorbottom:nil];
       [super viewDidUnload];
// Release any retained subviews of the main view.
}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)alert:(id)sender {


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle: @"Dismiss" otherButtonTitles: nil];

[alert show];

}

- (void)performAnimation:(NSNotification *)aNotification {

    // Animation code.

CGRect doorbottomFrame = doorbottom.frame;
doorbottomFrame.origin.y = self.view.bounds.size.height;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

doorbottom.frame = doorbottomFrame;

[UIView commitAnimations];

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Air", CFSTR
                                          ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundID);
AudioServicesPlaySystemSound (soundID);

  }
@end

在初始应用程序luanch之后调用的第一个方法是,
application:didfinishlaunchwithoptions:
因此,请调用其中的动画,而不是
viewdiload

您将在应用程序代理中找到此
应用程序:didfishlaunchingwithoptions:
方法

生命周期


这张图片的所有功劳都归于:

在初始应用程序luanch之后调用的第一个方法是,
应用程序:didFinishLaunchingWithOptions:
因此,请在其中调用动画,而不是
viewDidLoad

您将在应用程序代理中找到此
应用程序:didfishlaunchingwithoptions:
方法

生命周期


这张图片的全部功劳归于:

如果您需要一个事件只发生一次,您可以在AppDelegate类中创建一个bool属性,并在第一次设置UIView动画时将其设置为true。例如:

    - (void)viewDidLoad
    {

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    BOOL animated =appDelegate.animated;
    if(!animated)
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performAnimation:) name:UIApplicationDidBecomeActiveNotification   object:nil];
        appDelegate.animated =YES;
    }

     [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.

 }

如果需要一个事件只发生一次,可以在AppDelegate类中创建一个bool属性,并在第一次设置UIView动画时将其设置为true。例如:

    - (void)viewDidLoad
    {

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    BOOL animated =appDelegate.animated;
    if(!animated)
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performAnimation:) name:UIApplicationDidBecomeActiveNotification   object:nil];
        appDelegate.animated =YES;
    }

     [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.

 }

马特·德伦斯和保罗·沃伦在他们的iOS食谱书中非常全面地介绍了这一点。 解释相关章节: 假设您在加载过程中使用default.png作为一种启动屏幕,那么您需要将动画封装在它自己的视图控制器中,并且呈现为应用程序根视图控制器之外的模式视图控制器

在这里,计时是关键,根控制器的视图必须在显示模态视图控制器之前就位 因此,在didFinishLaunchingWithOptions中,您将:

  • 实例化包含splashscreen动画视图控制器的navcontroller视图
  • 将该导航控制器作为子视图添加到窗口中
  • 以模态方式呈现导航控制器-

有一些细节需要考虑,比如是否显示状态栏。。。Drance/Warren的书包括源代码和更为详尽的解释。

Matt Drance和Paul Warren在他们的iOS食谱书中非常详尽地介绍了这一点。 解释相关章节: 假设您在加载过程中使用default.png作为一种启动屏幕,那么您需要将动画封装在它自己的视图控制器中,并且呈现为应用程序根视图控制器之外的模式视图控制器

在这里,计时是关键,根控制器的视图必须在显示模态视图控制器之前就位 因此,在didFinishLaunchingWithOptions中,您将:

  • 实例化包含splashscreen动画视图控制器的navcontroller视图
  • 将该导航控制器作为子视图添加到窗口中
  • 以模态方式呈现导航控制器-

有一些细节需要考虑,比如是否显示状态栏。。。Drance/Warren的书中包含了源代码和更详尽的解释。

在我自己的项目中,我通过一个特殊的视图控制器来处理启动屏幕,我在我的应用程序委托中实例化了该控制器:

SDSSplashViewController* splash = [[SDSSplashViewController alloc] init];
[window addSubview:splash.view];
SDSSplashViewController
在其
viewDidLoad
中调用与您的
performAnimation
等效的函数。在动画结束时,将从其superview中删除视图。 这是非常干净和伟大的重复使用

如果希望视图控制器只执行一次,则可以在ApplicationIDFinishLaunching中实例化视图控制器(如上所述);如果希望在每次应用程序激活时执行动画(这是您在代码中所做的),则可以在ApplicationIDFinishLaunching中实例化视图控制器

关于您当前的问题:我假设您在xib文件中定义了doorbottom视图(因为您不在viewDidLoad中,也不提供loadView)

在这种情况下,所发生的是:每次加载视图时,它都按照您在xib中定义的方式加载。因此,如果它在那里可见,并且与视图的其余部分重叠,则当您不设置动画时,它将保持这种状态。一个简单的解决方法是将可设置动画的视图
隐藏在xib中,然后在
performAnimation
中首先将其取消隐藏:

- (void)performAnimation:(NSNotification *)aNotification {

   // Animation code.

   doorbottom.hidden = NO;
   ...

希望有帮助。

在我自己的项目中,我通过一个特殊的视图控制器来处理启动屏幕,我在我的应用程序委托中实例化了该控制器:

SDSSplashViewController* splash = [[SDSSplashViewController alloc] init];
[window addSubview:splash.view];
SDSSplashViewController
在其
viewDidLoad
中调用与您的
performAnimation
等效的函数。在动画结束时,将从其superview中删除视图。 这是非常干净和伟大的重复使用

如果希望视图控制器只执行一次,则可以在ApplicationIDFinishLaunching中实例化视图控制器(如上所述);如果希望在每次应用程序激活时执行动画(这是您在代码中所做的),则可以在ApplicationIDFinishLaunching中实例化视图控制器

关于您当前的问题:我假设您在xib文件中定义了doorbottom视图(因为您不在viewDidLoad中,也不提供loadView)

在这种情况下,所发生的是:每次加载视图时,它都按照您在xib中定义的方式加载。因此,如果它在那里可见,并且与视图的其余部分重叠,则当您不设置动画时,它将保持这种状态。一个简单的解决方法是将