小编Mee*_*shi的帖子

如何以PDF格式获取UITableView的快照

我有一个UITableView填充了一些数据,但由于它包含的数据比屏幕的可视区域更多的单元格,我只能设法得到它的快照,我想知道是否有其他方法我可以获得整个tableview快照在pdf ..这是我尝试过的感谢

- (IBAction)clickMe:(id)sender
{
    UIView *viewToRender = self.myTableView;
    CGPoint contentOffset = self.myTableView.contentOffset;

    UIGraphicsBeginImageContext(viewToRender.bounds.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    //  KEY: need to translate the context down to the current visible portion of the tablview
    CGContextTranslateCTM(ctx, 0, -contentOffset.y);

    [viewToRender.layer renderInContext:ctx];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIImageView *myImage=[[UIImageView alloc]initWithImage:image];

    UIGraphicsEndImageContext();

    [self createPDFfromUIViews:myImage saveToDocumentsWithFileName:@"PDF Name"];

}



- (void)createPDFfromUIViews:(UIView *)myImage saveToDocumentsWithFileName:(NSString *)string
{
    NSMutableData *pdfData = [NSMutableData data];

    UIGraphicsBeginPDFContextToData(pdfData, myImage.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and …
Run Code Online (Sandbox Code Playgroud)

pdf-generation uitableview ios

8
推荐指数
2
解决办法
5355
查看次数

获取标签动画与Phibrow App相同

我想创建与Phibrow App相同的动画.有关详细信息,请参阅以下视频: - https://www.dropbox.com/s/wwc69a9ktaa52je/IMG_0155.MOV?dl=0

在此输入图像描述 在此输入图像描述 在此输入图像描述

我试图用这个动画制作UIPinchGestureRecognizer,UIRotationGestureRecognizerUIPanGestureRecognizer.但还不能得到这个动画.

func handlePinchGesture(gesture: UIPinchGestureRecognizer) {
    if gesture.state == UIGestureRecognizerState.began || gesture.state == UIGestureRecognizerState.changed{
        //print("UIPinchGestureRecognizer")

        gesture.view?.transform = (gesture.view?.transform)!.scaledBy(x: gesture.scale, y: gesture.scale)
        gesture.scale = 1.0
    }
}


func handleRotationGesture(gesture: UIRotationGestureRecognizer) {
    if gesture.state == UIGestureRecognizerState.began || gesture.state == UIGestureRecognizerState.changed{
        print("UIRotationGestureRecognizer : ", gesture.rotation)
        gesture.view?.transform = (gesture.view?.transform)!.rotated(by: gesture.rotation)
        gesture.rotation = 0
    }
}

func handlePanGesture(gesture: UIPanGestureRecognizer) {
    if gesture.state == UIGestureRecognizerState.began || gesture.state == UIGestureRecognizerState.changed{
        //print("UIPanGestureRecognizer")
        let translation = gesture.translation(in: view) …
Run Code Online (Sandbox Code Playgroud)

animation gestures ios swift

8
推荐指数
1
解决办法
300
查看次数

iOS - MKMapView - 可拖动注释

我准备好了注释,但试着弄清楚如何使用我的代码使其可拖动:

-(IBAction) updateLocation:(id)sender{

    MKCoordinateRegion newRegion;

    newRegion.center.latitude = mapView.userLocation.location.coordinate.latitude;
    newRegion.center.longitude = mapView.userLocation.location.coordinate.longitude;

    newRegion.span.latitudeDelta = 0.0004f;
    newRegion.span.longitudeDelta = 0.0004f;

    [mapView setRegion: newRegion animated: YES];


    CLLocationCoordinate2D coordinate;
    coordinate.latitude = mapView.userLocation.location.coordinate.latitude;
    coordinate.longitude = mapView.userLocation.location.coordinate.longitude;

    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];

    [annotation setCoordinate: coordinate];
    [annotation setTitle: @"Your Car is parked here"];
    [annotation setSubtitle: @"Come here for pepsi"];


    [mapView addAnnotation: annotation];
    [mapView setZoomEnabled: YES];
    [mapView setScrollEnabled: YES];
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

xcode annotations draggable mkmapview ios

7
推荐指数
1
解决办法
1万
查看次数

UILabel SizeToFit的UITableView在滚动时会变得混乱

大家好我对我有问题tableview,我制作Cell with uilabelwith SizeToFit然后计算UILabel高度设置单元格高度一切正常,除非我滚动我tableView的文本变得奇怪,如每行一个字符:

我的TableViewVell方法是:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}


UILabel *label = (UILabel *)[cell viewWithTag:1];
label.text = [someArray objectAtIndex:indexPath.row];
// Set the UILabel to fit my text;
messageLabel.lineBreakMode = UILineBreakModeWordWrap;
messageLabel.numberOfLines = 0;
[messageLabel sizeToFit];


return cell;   
}
Run Code Online (Sandbox Code Playgroud)

Cell Height保持正确的大小问题只有UILabel...这是我加载视图时的结果: …

objective-c uitableview uilabel ios sizetofit

7
推荐指数
2
解决办法
5254
查看次数

如何在iOS中的UITableViewCell中播放视频(自动播放)

我正在播放视频UITableViewCell.为此,我使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *VideoCellIdentifier = @"VideoCell";

    NSDictionary *_response_data = [self.response objectAtIndex:indexPath.row];

    VideoCustomCell *cell = (VideoCustomCell *) [tableView dequeueReusableCellWithIdentifier:VideoCellIdentifier];

    if (cell == nil) {
        NSArray *topLevelObjects;
        topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"VideoCustomCell" owner:self options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (VideoCustomCell *) currentObject;
                cell.delegate  = self;
                break;
            }
        }
    }

    avPlayer = [[AVPlayer playerWithURL:[NSURL URLWithString:[_response_data valueForKey:@"media_id"]]] retain];
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
    avPlayerLayer.frame = cell.video_player_view.layer.bounds;
    avPlayerLayer.videoGravity = AVLayerVideoGravityResize;
    [cell.video_player_view.layer …
Run Code Online (Sandbox Code Playgroud)

video objective-c uitableview ios avplayer

7
推荐指数
1
解决办法
7950
查看次数

用于启动Google地图的网址架构在iOS 9中投放警告但也无法正常工作

以下代码在iOS 8.4及更早版本中运行良好,但是从iOS 9.0开始,它false始终会发出警告.

[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps-x-callback://"]]
Run Code Online (Sandbox Code Playgroud)

警告如下:

-canOpenURL: failed for URL: "comgooglemaps-x-callback://" - error: "This app is not allowed to query for scheme comgooglemaps-x-callback"
Run Code Online (Sandbox Code Playgroud)

有没有人知道,为什么它在iOS 9中失败以及为什么抛出错误This app is not allowed to query for scheme comgooglemaps-x-callback,是否需要查询它的任何权限?

编辑

我在info.plist中添加了以下项目,但它仍然存在同样的问题.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
    <string>comgooglemaps-x-callback</string>
</array>
Run Code Online (Sandbox Code Playgroud)

google-maps objective-c url-scheme ios ios9

7
推荐指数
1
解决办法
3538
查看次数

如何从照片的自定义相册,iOS SDK获取图像?

我正在开发一个iOS应用程序,我需要像Instagram这样的画廊视图.我已经添加了图库视图,相机视图和视频视图,在拍摄图像后,它会保存到照片的自定义相册中.现在我想从自定义相册中检索这些图像并将其显示到Gallery的Collection视图.但是我在从自定义相册中检索这些图片时遇到困难.任何帮助将不胜感激. 检查图片以获取参考

编辑:我添加了用于创建自定义相册的PHPhotoLibrary,在此之前我添加了AssetsLibrary框架.

然后我创建了一个NSObject类(CustomAlbum),用于使用PHPhotoLibrary创建和管理自定义相册.

// CustomAlbum.h

#import <Foundation/Foundation.h>
#import <Photos/Photos.h>


@interface CustomAlbum : NSObject

//Creating album with given name
+(void)makeAlbumWithTitle:(NSString *)title onSuccess:(void(^)(NSString *AlbumId))onSuccess onError: (void(^)(NSError * error)) onError;

//Get the album by name
+(PHAssetCollection *)getMyAlbumWithName:(NSString*)AlbumName;

//Add a image
+(void)addNewAssetWithImage:(UIImage *)image toAlbum:(PHAssetCollection *)album onSuccess:(void(^)(NSString *ImageId))onSuccess onError: (void(^)(NSError * error)) onError;

//get the image using identifier
+ (void)getImageWithIdentifier:(NSString*)imageId onSuccess:(void(^)(UIImage *image))onSuccess onError: (void(^)(NSError * error)) onError;


@end
Run Code Online (Sandbox Code Playgroud)

// CustomAlbum.m

#import "CustomAlbum.h"

@implementation CustomAlbum

#pragma mark - PHPhoto

+(void)makeAlbumWithTitle:(NSString *)title onSuccess:(void(^)(NSString *AlbumId))onSuccess onError: (void(^)(NSError * …
Run Code Online (Sandbox Code Playgroud)

objective-c ios phphotolibrary

7
推荐指数
2
解决办法
8951
查看次数

调用alloc init时,UIImagePickerController确实很慢

我有一个视图控制器,按下tabBarController中的一个选项卡.在这个视图控制器中,我在viewDidLoad方法中初始化一个UIImagePickerController:

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Set imagePicker
    //-------------------------//
    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.videoMaximumDuration = 10.0f;
}
Run Code Online (Sandbox Code Playgroud)

目的是在稍后按下按钮时显示UIImagePickerController.出于某种原因,虽然为此视图控制器按下选项卡图标时,此viewDidLoad方法正在运行时有3-4秒的挂起.当我注释掉行_imagePicker = [[UIImagePickerController alloc] init]时,没有挂起时间,视图控制器立即加载 - 应该如此.

有谁知道为什么分配和初始化UIImagePickerController需要这么长时间?如果是这样,除了将其作为后台进程运行之外,有没有办法加快速度?看来这不是正常行为.

我使用的是iOS7,我没有调用viewWillAppear或viewDidAppear.

performance objective-c uiimagepickercontroller ios

6
推荐指数
1
解决办法
3142
查看次数

无法在swift中的UIImageView中显示*.gif文件

我有一个*.gif文件,我想在一个UIImageView.我已经尝试过FLAnimatedImage库,代码如下.结果只是一个静态图像.

class LoginVC: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var img_popup: FLAnimatedImageView!

    var img_popupraw: FLAnimatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfFile: "ShitTalk_LoadingAnimation.gif"))

    override func viewDidLoad() {
        img_popup.animatedImage = img_popupraw
    }
}
Run Code Online (Sandbox Code Playgroud)

打开任何其他方法直接从gif文件显示动画gif.我正在使用Swift.

gif uiimageview ios swift

6
推荐指数
1
解决办法
2万
查看次数

如何在iOS中的CollectionView的页脚中添加加载指示器

如何为下一页加载数据时,如何在集合视图的页脚中添加加载指标?

在此输入图像描述

我想在Footer of Collection视图中加载指标与上图相同.但我无法做到这一点.

那可能与否......?否则,我必须使用tableview创建这种类型的列表视图.因为我们可以轻松地将这些东西管理成tableview.

任何帮助,将不胜感激.

objective-c uitableview ios uicollectionview swift

6
推荐指数
3
解决办法
8180
查看次数