我尝试了下一个:
UIDevice.currentDevice().setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: "orientation")
Run Code Online (Sandbox Code Playgroud)
上
viewWillAppear
Run Code Online (Sandbox Code Playgroud)
但它不起作用.如何在viewWillAppear上旋转屏幕?
UPDATE
我使用下一个代码来锁定方向:
var shouldRotate = true
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
if shouldRotate == true {
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
} else {
return Int(UIInterfaceOrientationMask.LandscapeLeft.rawValue)
}
}
Run Code Online (Sandbox Code Playgroud)
Swift 4.0
private func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
if shouldRotate == true {
return Int(UIInterfaceOrientationMask.portrait.rawValue)
} else {
return Int(UIInterfaceOrientationMask.landscapeLeft.rawValue)
}
}
Run Code Online (Sandbox Code Playgroud)
在我的第一个控制器viewWillAppear我设置:
if let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
appDelegate.shouldRotate = true
}
Run Code Online (Sandbox Code Playgroud)
在我的SECOND控制器中:
if let appDelegate = …Run Code Online (Sandbox Code Playgroud) 我想将标签文本设置为System Thin.读入StackOverflow并找到如下答案:
labelDescriptionView.font = UIFont(name: "System-Thin", size: 15.0)
Run Code Online (Sandbox Code Playgroud)
但它不起作用.如何以编程方式改进代码并制作Thin字体样式?
你怎么能看到我的imageView没有覆盖全屏.我怎么能这样做我的imageView将覆盖全屏和dotView上的点?
我用viewController + PageViewController做到了.
我调整它的大小:
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height)
Run Code Online (Sandbox Code Playgroud)
我的代码很长,所以如果你想查看我的代码的确切部分 - 只需询问它
我有一个表格:
<form class="searchForm">
<div class="box_style_1">
<h4><?= Yii::t("common", "Age"); ?></h4>
<?
echo '<b class="badge">3</b> ' . Slider::widget([
'name'=>'age',
'value'=>'250,650',
'sliderColor'=>Slider::TYPE_GREY,
'pluginOptions'=>[
'min'=>3,
'max'=>21,
'step'=>1,
'range'=>true
],
]) . ' <b class="badge">21</b>';
?>
<br /><br />
<input type="submit" value="Search" class="searchByAge"/>
<br /><br />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
并希望在console.log中显示结果:
$('.searchByAge').on('click', function(e){
e.preventDefault();
var range = $('.form-control').val();
var min = range.split(',')[0];
var max = range.split(',')[1];
//alert(min+' '+max);
$.ajax({
type: 'POST',
url: '/age/'+min+'/'+max,
data: $('.searchForm').serialize(),
success: function (data) {
console.log(data);
},
error: function(jqXHR, textStatus, errorMessage) {
console.log(errorMessage); …Run Code Online (Sandbox Code Playgroud) 我用下一个代码:
var camera = GMSCameraPosition.cameraWithLatitude(40.378259,
longitude: 49.875059, zoom: 16)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(40.378259, 49.875059)
marker.map = mapView
Run Code Online (Sandbox Code Playgroud)
我使用约束,但它对我没有帮助.即使我执行下一个操作,我的地图也会全屏显示:
var mapView = GMSMapView.mapWithFrame(CGRectMake(0, 0, 100, 100), camera: camera)
Run Code Online (Sandbox Code Playgroud)
为什么它不起作用?我该如何解决?我通过Podfile连接它
我有一个公共职能:
public func lastActivityFor(userName: String) -> String { ... }
Run Code Online (Sandbox Code Playgroud)
后来我想把它称为:
OneLastActivity.lastActivityFor("username")
Run Code Online (Sandbox Code Playgroud)
但最后一行得到错误:
Cannot convert value of type 'String!' to expected argument type 'OneLastActivity'
Run Code Online (Sandbox Code Playgroud)
为什么我按照建议发送给那些函数String?(userName: String)
任何想法我该如何解决?如果你想要更多代码,请问我.
为什么我无法将JSON响应中的String值转换为Int?它返回下一个错误:
Cannot invoke initializer for type 'Int' with an argument list of type '(JSON)'
Run Code Online (Sandbox Code Playgroud)
当我尝试:
Int(json[i]["id"])
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它转换为Int?
我想编写一个函数alert()并运行它.但我想在任何控制器中显示此警报而不重复代码.
例如:我有Presence.swift类,这里我有一些条件,如:
if myVar == 1 { // Just for presenting
runMyAlert()
}
Run Code Online (Sandbox Code Playgroud)
当在后台myVar == 1用户时,无论他在哪里,在哪个屏幕上,他都会在屏幕上获得警报.
如何在不重复代码的情况下完成?我试图在AppDelegate中做到:
func alert(title : String,message : String,buttonTitle : String,window: UIWindow){
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertActionStyle.Default, handler: nil))
window.rootViewController?.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
称之为:
if myVar == 1 {
AppDelegate().alert()
}
Run Code Online (Sandbox Code Playgroud) 如何使搜索栏的颜色变为蓝色?
我试过了:
searchBar.opaque = true
Run Code Online (Sandbox Code Playgroud)
也
searchBar.translucent = false
Run Code Online (Sandbox Code Playgroud)
但这行不通。为什么?
ios ×9
swift ×9
iphone ×2
ajax ×1
alert ×1
appdelegate ×1
fonts ×1
google-maps ×1
javascript ×1
jquery ×1
json ×1
orientation ×1
php ×1
tags ×1
uisearchbar ×1
xcode ×1
yii2 ×1