启动画面的操作

   有些项目需要自己手动设计启动画面的方式,如图片的切换,给启动画面添加文本等;

    首先,启动画面的图片切换,一般做法是添加一个滑动界面,把图片放进界面,启动后跳到该界面;这样就可以实现滑动界面的启动画面。

    添加文本的启动界面,可以和上面的一样方法;不过还有一个简单的方法,代码如下:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
   

    //splashView在.h中定义

    _splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    _splashView.image = [UIImage imageNamed:@"Default.png"];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60, 200, 200, 30)];
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.text = @"welcome";
    [_splashView addSubview:label];
    [self.window addSubview:_splashView];
    [self.window bringSubviewToFront:_splashView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView: self.window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    _splashView.alpha = 0.0;
    _splashView.frame = CGRectMake(-60, -85, 440, 635);
    [UIView commitAnimations];
    
    return YES;
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [_splashView removeFromSuperview];
}

转载于:https://my.oschina.net/hong90/blog/198251

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在PyQt中,可以通过自定义启动画面来增加应用程序的专业感和用户体验。下面是一种实现自定义启动画面的方法: 1. 创建一个新的启动画面窗口类,继承自QMainWindow或QWidget。 2. 在该类中,可以添加自定义的UI元素,例如Logo、进度条等。 3. 在启动画面窗口类的构造函数中,设置窗口的样式、大小和位置等属性。 4. 在应用程序的主窗口类中,创建一个启动画面窗口对象,并在应用程序启动时显示该窗口。 5. 在应用程序初始化过程中,可以执行一些耗时的操作,例如加载资源、初始化数据等。 6. 在耗时操作完成后,关闭启动画面窗口,并显示应用程序的主窗口。 下面是一个简单的示例代码,演示了如何实现自定义启动画面: ```python from PyQt5.QtWidgets import QApplication, QMainWindow, QSplashScreen, QLabel from PyQt5.QtGui import QPixmap from PyQt5.QtCore import Qt, QTimer class SplashScreen(QMainWindow): def __init__(self): super().__init__() self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setFixedSize(400, 300) # 添加自定义UI元素 label = QLabel(self) pixmap = QPixmap('logo.png') label.setPixmap(pixmap) label.setAlignment(Qt.AlignCenter) self.show() class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle('My Application') self.setGeometry(100, 100, 800, 600) # 执行耗时操作 self.load_data() self.show() def load_data(self): # 模拟耗时操作 QTimer.singleShot(3000, self.close_splashscreen) def close_splashscreen(self): self.splashscreen.close() if __name__ == '__main__': app = QApplication([]) # 创建启动画面窗口对象 splashscreen = SplashScreen() # 创建应用程序主窗口对象 mainwindow = MainWindow() mainwindow.splashscreen = splashscreen app.exec_() ``` 在上述示例代码中,SplashScreen类是自定义的启动画面窗口类,MainWindow类是应用程序的主窗口类。在MainWindow类中,通过load_data()方法模拟了一个耗时操作,并使用QTimer.singleShot()方法延迟3秒后关闭启动画面窗口。 请注意,上述示例代码中使用了Qt的定时器来模拟耗时操作,实际应用中需要根据具体需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值