嗨,我正在玩iPhone上的位置,从一开始我遇到了问题.我已经解决了我的问题,并确定这CLLocationManager是困扰我的.
所以我开发了非常简单的应用.我只有一个带有a的视图控制器CLLocationManager.在视图上加载我初始化CLLocationManager并开始更新.我也实现了两个方法didFailWithError和didUpdateToLocation.
我已经阅读了很多问题以及我学到了什么,所以这就是这个.您必须CLLocationManager在初始化期间保留.此外,它是明智的设置CLLocationManagers delegate,以nil卸载的过程中view(用的东西传递到信息办CLLocationManager,因为框架保留它,它从来没有正确地释放)
总而言之,我无法找到关于如何做以及如何使其发挥作用的合理解释.
这是我的代码,所以如果有人能搞清楚,我会很感激.
viewControllers头文件
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface CoreLocationViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locManager;
}
@property (nonatomic, retain) CLLocationManager *locManager;
@end
Run Code Online (Sandbox Code Playgroud)
viewController .m文件
#import "CoreLocationViewController.h"
@implementation CoreLocationViewController
@synthesize locManager;
- (void)viewDidLoad
{
[super viewDidLoad];
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
[self.locManager startUpdatingLocation];
self.view.backgroundColor = [UIColor grayColor];
}
#pragma mark -
#pragma mark …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我使用AFNetworking从网上下载数据.我正在利用NSURLRequestUseProtocolCachePolicy我NSURLRequest来提供用户缓存数据(如果缓存有效).这是我的代码:
请求方法:
// create NSURL request
NSURLRequest *request = [ServerFactory URLGETRequestWithURL:url];
//creating AFHTTPRequestOperation
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
//set serializaer
operation.responseSerializer = [AFJSONResponseSerializer serializer];
//need to specify that text is acceptable content type, otherwise the error occurs
operation.responseSerializer.acceptableContentTypes = [MyRepository acceptableContentTypes];
//running fetch request async
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//parse data
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handling
}];
//start async operation
[operation start];
Run Code Online (Sandbox Code Playgroud)
可接受的内容类型方法
+ (NSSet *)acceptableContentTypes
{
return [NSSet setWithObjects:@"application/json", …Run Code Online (Sandbox Code Playgroud) 我试图同时缩放和裁剪图像并从左到右屏幕边缘显示它。我收到的图像只比用户屏幕宽一点,我可以像这样缩放它(XML):
<ImageView
android:id="@+id/category_image_top"
android:layout_width="match_parent"
android:layout_height="170dp"
android:maxHeight="170dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:focusable="false"
/>
Run Code Online (Sandbox Code Playgroud)
但这就是我得到的:

我想将图像对齐到右上角,如下所示:

这可能吗?我已经尝试了所有的scaleTypes,但注意到有效,图像要么缩放以适合X和Y(fitXY,fitStart),要么裁剪图像但居中(centerCrop)。我需要类似 android:scaleType="cropStart"