如何获取当前位置的经纬度.
我试过这个.使用Xcode 6.01和IOS SDK 8.0
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}
- (void)viewDidLoad{
[super viewDidLoad];
[self getCurrentLocation];
}
Run Code Online (Sandbox Code Playgroud)
在这里,我将模拟器位置启用到Deployment 8.0 iPhone模拟器4s.即使在设备上也无法正常工作.
@ALL请告诉我,我在这里做错了什么.
core-location cllocationmanager cllocation currentlocation ios8
从Xcode项目右键单击并Add File to "projectName"在那里我创建了一个NewFolder "ABCD"名称并添加到相同的"ABCD"空文件夹到项目的蓝色,我期望它在黄色,我在Blue Color文件夹文件中添加的文件没有编译在X-Code中,在Blue Color文件夹中添加的所有文件都说在编译代码后找不到文件.
有没有为什么默认,我添加的文件夹是与项目相关的链接?
这个问题对我来说非常奇怪,您的反馈非常有帮助.
UIBarButtonItem为它创建了添加的Power Image.
barBtnPower = new UIBarButtonItem (UIImage.FromBundle ("Images/Power@2x.png")
, UIBarButtonItemStyle.Plain
, (sender, args) => {
});
Run Code Online (Sandbox Code Playgroud)
按钮添加到右侧的导航项目.
this.NavigationItem.SetRightBarButtonItem (barBtn_Logout, true);
Run Code Online (Sandbox Code Playgroud)
问题是Power@2x.png是绿色.但运行应用程序后,它显示为蓝色.
任何人都可以在这里建议我做错了什么.
键盘未出现在模拟器上的文本字段中.
创建了文本字段.
txt_UserName = new UITextField {
Placeholder = "Enter Username",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
LeftViewMode = UITextFieldViewMode.Always,
ReturnKeyType = UIReturnKeyType.Next,
BackgroundColor = UIColor.White,
ShouldReturn = delegate {
txt_Email.BecomeFirstResponder ();
return true;
}
};
txt_Email = new UITextField {
Placeholder = "Enter Email",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
KeyboardType = UIKeyboardType.EmailAddress,
LeftViewMode = …Run Code Online (Sandbox Code Playgroud) 选择器视图与工具栏,创建完成按钮上.单击完成按钮,它不起作用.
选择器视图向上滚动.点击完成按钮.
-(void)createPicker:(id)sender{
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,100,0,0)];
[pickerView setDataSource: self];
[pickerView setDelegate: self];
pickerView.showsSelectionIndicator = YES;
[pickerView setBackgroundColor:[UIColor whiteColor]];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
toolBar.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTouched:)];
[toolBar setItems:[NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], doneButton, nil]];
[pickerView addSubview:toolBar];
}
Run Code Online (Sandbox Code Playgroud)
点击完成按钮关闭pickerView
-(void)doneTouched:(id)sender{
[pickerview removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
我不知道我在这里做错了什么.任何人都可以建议我如何调用uipickerview工具栏按钮上添加的完成按钮方法.
点击完成选择器视图向上滚动,而不是调用doneTouched方法:
@All先谢谢.
在使用Xamarin 5.4(build 240)在mac OSX 10.9.4上更新iOS 8之后.
在模拟器应用程序上运行应用程序运行正常.
当我连接我的设备并运行时,我收到以下错误消息.
Error MT5203: Failed to generate the debug symbols (dSYM directory). Please review the build log. (MT5203) (ProjectName)
Run Code Online (Sandbox Code Playgroud)
更新之前它在设备和模拟器上成功运行.
使用xamarin作为当前位置currentLocation示例
我使用上面的Link获取当前位置的纬度和经度.
在升级到IOS 8之前的IOS 7中它在模拟器和设备上显示我当前位置的纬度和经度.(在模拟器中看起来很奇怪,获取当前位置的纬度和经度).
升级到iOS 8并运行相同的代码后,它会给出
在模拟器中:(开启wifi无SIM卡位置服务应用程序总是.)
Result:
latitude = 37.785834.
longitude = -122.406517.
Run Code Online (Sandbox Code Playgroud)
在设备IPhone5c上(始终打开wifi无SIM卡位置服务应用程序.)
Result:
latitude = 37.785834.
longitude = -122.406517.
Run Code Online (Sandbox Code Playgroud)
(但我预计我目前的位置纬度和经度)
升级后它没有问,该应用程序就像使用你的当前位置GPS.带有YES,NO选项的警报消息.
如何获取我当前的位置纬度和经度?
如何将Image转换为base64String.
UIImage * someImage = [UIImage imageNamed: @"page4.png"];
NSData *imageData = UIImageJPEGRepresentation(someImage, 1.0);
// NSString *encodedString = [imageData base64EncodedDataWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSString *base64 = [[NSString alloc] initWithData:imageData encoding:NSUTF8StringEncoding] ;
if (base64){
NSLog(@"Base 64 %@",base64);
}
Run Code Online (Sandbox Code Playgroud)
我上面的代码给了我base64字符串的空值.
@All先谢谢.
当将UITabbar上的UIButton添加到中间时如图所示。UITabBar上面的按钮动作无法点击
func setupMiddleButton() {
plusButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var menuButtonFrame = plusButton.frame
menuButtonFrame.origin.x = tabBar.bounds.width/2 - menuButtonFrame.size.width/2
let hasNotched :Bool? = UIDevice.current.hasNotch
if hasNotched != nil {
menuButtonFrame.origin.y = tabBar.bounds.height - menuButtonFrame.height - 15
} else {
menuButtonFrame.origin.y = tabBar.bounds.height - menuButtonFrame.height - 50
}
plusButton.frame = menuButtonFrame
plusButton.setTitle("+", for: .normal)
plusButton.titleLabel?.font = UIFont.helveticaNeue(ofSize: 40)
plusButton.backgroundColor = UIColor.init(hexString: "5E71FE")
plusButton.titleEdgeInsets = UIEdgeInsets(top: 0,left: 10,bottom: 10,right: 10)
tabBar.addSubview(plusButton)
plusButton.layer.cornerRadius = menuButtonFrame.height/2
plusButton.addTarget(self, action: #selector(plusButtonAction(sender:)), …Run Code Online (Sandbox Code Playgroud) 从给定的枚举中选择随机值
public class SwiftConfettiView: UIView {
public enum ConfettiType {
case confetti
case triangle
case star
case diamond
case image(UIImage)
}
Run Code Online (Sandbox Code Playgroud)
// 在其他类中的用法
confettiView.type = .confetti
Run Code Online (Sandbox Code Playgroud)
想随机设置五彩纸屑查看三角形、星形、菱形、五彩纸屑
//这行不通
confetti.type = ConfettiType.allCases.randomElement()!
Run Code Online (Sandbox Code Playgroud)
类型 'SwiftConfettiView.ConfettiType' 没有成员 'allCases'
//所以,所有的五彩纸屑到一个数组列表并从那里加载!
var confettiList = [SwiftConfettiView.ConfettiType.confetti
, SwiftConfettiView.ConfettiType.diamond
, SwiftConfettiView.ConfettiType.triangle
, SwiftConfettiView.ConfettiType.star
Run Code Online (Sandbox Code Playgroud)
]
confettiView.type = confettiList.randomElement()!
Run Code Online (Sandbox Code Playgroud)
它工作正常!
这种方法是对还是错?