`
天梯梦
  • 浏览: 13756987 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

延迟效果 (切换页面) Delay Actions (实例)

 
阅读更多

Delay Actions 

In this tutorial i will be showing you how to delay actions

Features:

  • 2 UILabels
  • 1 round rect button

Delaying action in you apps is very useful enabling you to hide content in your apps before revealing it to your user or create splash screens switching views to you main view after a certain period of time

 

The Code

Play the video to get a step by step walkthrough and all code can be copy and pasted

 

ViewController.h 

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    __weak IBOutlet UILabel *label1;
    __weak IBOutlet UILabel *label2;
}

- (IBAction)pushme:(id)sender;
- (void)delay1;
- (void)delay2;

@end

 

 Import a new view and name is secondview

 

ViewController.m

#import "ViewController.h"
#import "secondview.h"

- (void)viewDidUnload
{
    label1 = nil;
    label2 = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (IBAction)pushme:(id)sender 
{
    label1.text = @"In 5 seconds the second label will be displayed";
    [self performSelector:@selector(delay1) withObject:nil afterDelay:5.0];
}

- (void)delay1
{
    label2.text = @"In 5 seconds the view will switch";
    [self performSelector:@selector(delay2) withObject:nil afterDelay:5.0];
}

- (void)delay2
{
    secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:second animated:YES];
}

 

secondview.h

#import <UIKit/UIKit.h>

@interface secondview : UIViewController
{
    
}

- (IBAction)dismiss:(id)sender;

@end
 

secondview.w

- (IBAction)dismiss:(id)sender 
{
    [self dismissModalViewControllerAnimated:YES];
}
 

视频:http://www.youtube.com/watch?feature=player_embedded&v=lOp9-fiH3BI

 

分解:

 

1. @selector 是什么?


1、一种类型 SEL

2、代表你要发送的消息(方法), 跟字符串有点像, 也可以互转.: NSSelectorFromString()   /   NSSelectorFromString()

3、可以理解为类似函数指针的东西--是能让Objective-C动态调用方法的玩意.--是 object-c 的动态后绑定技术 可以通过字符串 访问的函数指针

4、其实就是消息响应函数---选一个消息响应的函数地址给你的action

5、@selector(function_name) 即取得一个function的id

 

参考: Objective-C 2.0 with Cocoa Foundation--- 5,Class类型,选择器Selector以及函数指针

 

2. 关于performSelector: withObject:afterDelay:方法

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
  

aSelector是你想调用的方法,可带一个参数或者是无参数,如果是一个参数的话这个参数必须是对象类型,如:NSString,NSArray之类的,不能是NSInteger这样的,

anArgument是你要传递

的参数,函数无参数时为nil,

delay:过多久调用这个方法.

 

3. initWithNibName 这个方法是在controller的类在IB中创建,但是通过Xcode实例化controller的时候用的.

 

4. presentModalViewController和dismissModalViewControllerAnimated

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
// Display another view controller as a modal child. Uses a vertical sheet transition if animated.

- (void)dismissModalViewControllerAnimated:(BOOL)animated;
// Dismiss the current modal child. Uses a vertical sheet transition if animated.
 

在iOS当中,若是要切换页面,除了使用Navigation外,也可以在UIViewController使用presentModalViewController方法,将其他的View推进来。

 

方法:

secondview *second= [[secondview alloc] initWithNibName:@"secondview" bundle:nil];
self presentModalViewController:second animated:YES];

 
用法很简单,只要将要推进来的View建立起来,再利用presentModalViewController方法即可。
若要将利用上述方法推进来的View退掉,就可以使用dismissModalViewControllerAnimated方法。

[self dismissModalViewControllerAnimated:YES];

 
但若是你的程式的架构比较复杂,比如说:在window上有超过一层的View,可能会在推进View的时候造成方向上的错乱,则可以利用设定modalPresentationStyle为UIModalPresentationCurrentContext来解决。

secondview.modalPresentationStyle = UIModalPresentationCurrentContext;

 
除了UIModalPresentationCurrentContext以外,还有三种PresentationStyle:
1. UIModalPresentationFormSheet:view以视窗的方式出现,很像网页上js遮照的效果。
2. UIModalPresentationFullScreen:整页覆盖。
3. UIModalPresentationPageSheet:直的时候是FullScreen效果,横的时候是FormSheet效果。

除了控制出现的区块,也可以控制出现的动画,利用设定modalTransitionStyle完成。

 

secondview.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

 

 

 

分享到:
评论

相关推荐

    vue使用keep-alive切换页面,2种方法实现页面保持滚动位置.zip

    在Vue.js应用中,我们经常需要使用路由进行页面间的切换,但默认情况下,当用户从一个页面切换到另一个页面时,之前的页面状态会被重置,包括滚动位置。为了解决这个问题,Vue提供了一个名为`keep-alive`的组件,它...

    ios-仿手机百度页面切换效果.zip

    这个"ios-仿手机百度页面切换效果.zip"项目就是一个实例,展示了如何在iOS应用中实现这样的动画。通过分析这个项目,我们可以学到以下几个关键的知识点: 1. **页面控制器(PageViewController)**: - iOS中的...

    linux-用于使用静态站点生成器部署到GitHub页面的GitHubActions

    用于使用静态站点生成器部署到GitHub页面的GitHub Actions

    vue实现页面切换滑动效果

    在Vue.js中实现页面切换滑动效果,可以借助Vue的内置组件`transition`以及`vue-router`来完成。`vue-router`用于处理页面间的路由跳转,而`transition`则负责过渡动画效果。以下将详细讲解如何实现这一功能。 首先...

    Actions 烧录工具windows版本

    Actions S900 S700 等固件烧录工具,居于windows平台烧录

    Android代码-actions

    Actions Library for user actions in the browser. Allows you to create various actions to implement them through Selemium WebDriver, combine them into test scenarios and serialize test scripts to XML. ...

    vue路由切换时取消之前的所有请求操作

    在Vue.js应用中,路由切换是常见的操作,但有时我们希望在用户切换路由时取消之前正在进行的网络请求,以避免不必要数据的加载或者错误的数据处理。本文将详细讲解如何在Vue路由切换时取消之前的所有请求操作。 ...

    媒体的选择方法—actions方法

    总结来说,"媒体的选择方法—actions方法"是一个全面的框架,它引导教育者在众多的教学媒体中做出明智的选择,以达到最佳的教学效果。在设计远程教育课程时,运用这个方法可以帮助我们更加系统地分析和决策,确保...

    PHOTOSHOP CS3.0实例素材

    同时,实例通常会涉及图层管理、蒙版应用、滤镜效果、文字编辑等高级功能,这对于提升技能至关重要。 在网页制作方面,Photoshop CS3.0也发挥了重要作用。它可以用来创建网页布局草图,预览网页设计效果。通过切片...

    ios-游标切换动画效果.zip

    在iOS开发中,游标切换动画效果是一种常见的用户界面交互设计,它通常用于导航或选择操作,例如在选项之间切换。这个"ios-游标切换动画效果.zip"压缩包文件包含了一个实现这种效果的示例项目,名为"DobleBtn"。这个...

    Vue全家桶之Vuex实例代码

    3. **Actions**:Actions用于发起异步操作或者触发一系列mutations。它们可以是包含复杂逻辑的函数,例如API调用。在`VuexTest`的`actions.js`中,可能会有类似`actionIncrement ({ commit }) { commit('increment')...

    通过 GitHub Actions 最大限度地提高效率:软件工程师的高级策略

    ### 通过 GitHub Actions 最大限度地提高效率:软件工程师的高级策略 在现代软件开发过程中,持续集成(CI)和持续交付(CD)已经成为提升工作效率和项目质量的关键环节。GitHub Actions 作为一种强大的工具,不仅...

    JSP系统开发与设计实例教程

    这些实例可以帮助你在实践中学习,从简单的页面展示到复杂的业务逻辑处理,逐步提升你的开发技能。 总的来说,"JSP系统开发与设计实例教程"是一个全面的资源,旨在帮助开发者从基础到高级,系统地学习和实践JSP开发...

    Avg_Del.awk.tar.gz_average delay

    这个名为 "Avg_Del.awk.tar.gz_average delay" 的压缩包文件包含了一个 `awk` 脚本,其主要目的是计算平均延迟时间。让我们深入探讨一下 `awk` 和如何使用它来计算平均值,以及在实际应用中可能涉及的相关知识点。 ...

    linux-一组实用的GitHubActions集合

    在这个名为"linux-一组实用的GitHubActions集合"的资源中,我们看到的是一个名为"actions-master"的压缩包,它很可能包含了与Linux和GitHub Actions相关的脚本或配置文件。 GitHub Actions 允许开发者自定义工作流...

    Actions SerialUtility-V2.3-20221108串口调试工具

    可自定义设置波特率

    C# PDF Page操作设置页面切换按钮的方法

    C# PDF Page操作设置页面切换按钮的方法 本文主要介绍了如何在 C# 中使用 Spire.PDF for .NET 库来实现 PDF 文档页面设置页面切换按钮的方法。该方法可以将按钮添加到 PDF 文档中,并实现按钮的跳转到指定页面、...

    JSP教程PPT及实例代码实现

    5. **动作(Actions)**:如`&lt;jsp:include&gt;`, `&lt;jsp:forward&gt;`, `&lt;jsp:param&gt;`等,它们用于在页面间传递参数或包含其他资源。 **四、JSP生命周期** JSP的生命周期包括三个主要阶段:加载、实例化和销毁。在实例化...

    Google语音命令_Voice_Actions

    【Google语音命令_Voice_Actions】是一款由Google开发的创新性应用,旨在让用户通过语音指令与手机进行互动,实现高效便捷的操作。这款软件是Google语音识别技术的重要组成部分,它不仅提升了用户在移动设备上的交互...

Global site tag (gtag.js) - Google Analytics