我在(?=[0-9])
中使用LaunchImage.launchimage
来管理启动图片。但我也试图在应用程序中使用启动图像。
我看过this answer:
文档指出UIImage上的 imageNamed:方法 应自动魔术选择正确的版本
所以,我使用了这段代码
Images.xcassets
在使用iPhone 4,5,6,6+时,它可以正常工作并获得正确的LaunchImage,但在处理 iPad视网膜时,它会返回UIImageView *backImage = [UIImageView new];
backImage.image = [UIImage imageNamed:@"LaunchImage"];
,这是LaunchImage的 iPhone 4s LaunchImage-700@2x.png
640 x 960 pixels
文件夹中的Contents.json
LaunchImage
答案 0 :(得分:2)
我使用长方法
解决了这个问题BOOL deviceIsIpad = NO;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
deviceIsIpad = YES;
}
if (!deviceIsIpad) {
backImage.image = [UIImage imageNamed:@"LaunchImage"];
} else {
UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
CGFloat screenScale = [[UIScreen mainScreen] scale];
if (interfaceOrientation == UIDeviceOrientationPortrait || interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){
if (screenScale > 1) {
backImage.image = [UIImage imageNamed:@"LaunchImage-700-Portrait@2x~ipad.png"];
} else {
backImage.image = [UIImage imageNamed:@"LaunchImage-700-Portrait~ipad.png"];
}
} else {
if (screenScale > 1) {
backImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape@2x~ipad.png"];
} else {
backImage.image = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"];
}
}
}
答案 1 :(得分:0)
我相信这些扩展(例如-700-Landscape @ 2x~ipad)无法识别。
将以下项目添加到Contents.json中仅用于测试目的:
class Users::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
protected
def after_sign_up_path_for(resource)
'/after_signup'
end
end
class AfterSignupController < ApplicationController
include Wicked::Wizard
steps :name, :username, :bio, :image
def show
binding.pry
@profile = current_user.profile
render_wizard(@profile)
end
def update
@profile = current_user.profile
@profile.update(profile_params)
render_wizard(@profile)
end
private
def profile_params
params.require(:profile).permit(:username, :first_name, :last_name, :bio, :image, :user_id)
end
end
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, profile_attributes: [:user_id, :first_name, :last_name, :username, :bio, :image])}
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :password_confirmation, profile_attributes: [:user_id, :first_name, :last_name, :username, :bio, :image])}
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :username, :email, :password, :remember_me) }
end
end
##name.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
<div class="field col-xs-8 col-sm-6">
<div class="field">
<%= f.text_area :first_name, autofocus: true %>
<%= f.text_area :last_name, autofocus: true %>
</div>
</div>
</div>
<% end %>
<div class="actions">
<%= f.submit "Next", :class => 'btn btn-primary' %>
or <%= link_to "skip", next_wizard_path %>
</div>
##username.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
<div class="field col-xs-8 col-sm-6">
<div class="field">
<%= f.text_area :username, :placeholder => 'username' autofocus: true %>
</div>
</div>
</div>
<% end %>
<div class="actions">
<%= f.submit "Next", :class => 'btn btn-primary' %>
or <%= link_to "skip", next_wizard_path %>
</div>
##bio.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
<div class="field col-xs-8 col-sm-6">
<div class="field">
<%= f.text_area :bio, autofocus: true %>
</div>
</div>
</div>
<% end %>
<div class="actions">
<%= f.submit "Next", :class => 'btn btn-primary' %>
or <%= link_to "skip", next_wizard_path %>
</div>
##image.html.erb
<%= bootstrap_form_for(@profile, url: wizard_path, method: :put) do |f| %>
<div class="row">
<div class="field col-xs-8 col-sm-6">
<div class="field">
<%= f.text_field :image, autofocus: true %>
</div>
</div>
</div>
<% end %>
<div class="actions">
<%= f.submit "Submit", :class => 'btn btn-primary' %>
</div>
现在尝试使用imageNamed:方法。
或尝试使用图像全名:
的imageNamed :.{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"filename" : "LaunchImage.png",
"scale" : "1x"
}
答案 2 :(得分:0)
<强> LaunchImage.launchimage 强>
您是否真的使用Images.xcassets
来管理启动图片?
你不是在使用LaunchImage.launchimage
吗?
如果是这样,就会出现混乱。您无法使用[UIImage imageNamed:@"LaunchImage"];
中的LaunchImage.launchimage
加载。
规范名称
LaunchImage.png
LaunchImage@2x.png
LaunchImage-700@2x.png
LaunchImage-568h@2x.png
LaunchImage-700-568h@2x.png
LaunchImage-700-Landscape@2x~ipad.png
LaunchImage-700-
人像 @2x~ipad.png
不。