小编ber*_*ium的帖子

将NSURL转换为NSString

我有一个应用程序,用户可以从内置的应用程序图像或从iPhone照片库中选择图像.我使用一个具有NSString保存属性的对象Occasion imagePath.

现在,在内置应用程序映像的情况下,我确实将文件名作为NSString一个保存[occasion imagePath].但是在用户从照片库中选择图像的第二种情况下,我得到了一个NSURL我想要转换为NSString能够将其保存在其中的图像[occasion imagePath.

是否有可能将其转换NSURLNSString

objective-c nsurl nsstring ios swift

333
推荐指数
4
解决办法
21万
查看次数

宽度和高度是否以编程方式使用autolayout等于superView?

我一直在网上寻找很多片段,我仍然无法找到问题的答案.我的问题是我有一个scrollView(SV),我想以编程方式在scrollView(SV)中添加一个按钮,其superview的相同宽度和高度是scrollView(SV),这样当用户旋转设备按钮时将具有相同的框架scrollView(SV).如何做NSLayout/NSLayoutConstraint?谢谢

dynamic ios autolayout nslayoutconstraint swift

80
推荐指数
6
解决办法
8万
查看次数

Swift:使用枚举在CoreData中存储状态

我想在CoreData中为托管对象存储枚举状态

enum ObjStatus: Int16 {
    case State1 = 0
    case State2 = 1
    case State3 = 3
}

class StateFullManagedObject: NSManagedObject {
    @NSManaged var state: Int16
}
Run Code Online (Sandbox Code Playgroud)

最后一步是将StateFullManagedObject的状态变量转换为ObjStatus以进行直接比较,这对我不起作用.例如,我不能在Int16和Int16枚举之间使用==运算符.我得到的编译时错误是

Int16无法转换为'MirrorDisposition'

.见下面的条件:

var obj: StateFullManagedObject = // get the object

if (obj.state == ObjStatus.State1) { // Int16 is not convertible to 'MirrorDisposition'

}
Run Code Online (Sandbox Code Playgroud)

如何在Int16和枚举之间进行比较/分配?

core-data swift

44
推荐指数
3
解决办法
2万
查看次数

MPMoviePlayerController的视图无法识别触摸

这是我的代码:

_mediaPlayer = [[MPMoviePlayerController alloc] init];
_mediaPlayer.controlStyle = MPMovieControlStyleNone;
_mediaPlayer.shouldAutoplay = NO;
[_mediaPlayer.view setFrame: CGRectMake(5, 5, 600,400)];
[playerHolder addSubview: _mediaPlayer.view];
//
[self prepareScreenContentToPlay];
//
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleRollTap:)];
singleFingerTap.numberOfTapsRequired = 1;
[_mediaPlayer.view addGestureRecognizer:singleFingerTap];
[singleFingerTap release];
Run Code Online (Sandbox Code Playgroud)

和手势识别器的动作方法:

-(void)handleRollTap:(UITapGestureRecognizer*)sender{
    NSLog(@"%@", @"touch");
}
Run Code Online (Sandbox Code Playgroud)

MPMoviePlayerController工作正常.另外我想处理MPMoviePlayerController视图上的触摸但handleRollTap从未调用过.为什么MPMoviePlayerController的视图不适用于UITapGestureRecognizer?


好.如果singleFingerTap.numberOfTapsRequired = 2;那时一切正常.但没有什么可以单击...


mpmovieplayercontroller ipad uigesturerecognizer ios

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

UIControl未接收到触摸

我有一个UIControl实现了触摸开始方法,如下所示:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    //More code goes here
Run Code Online (Sandbox Code Playgroud)

UIControl的这个子类在视图控制器中实例化,然后作为子视图添加到该视图控制器.我在UIControl的touches begin方法中有一个断点,并且该方法永远不会被调用.我一直在做一些阅读,看起来View Controller有一些逻辑决定是否将触摸事件传递给它的子视图.奇怪的是,我在同一个视图控制器中有一个不同的UIControl子类,触摸事件在用户触摸时传递给它!这是完整的代码:

.H

#import <UIKit/UIKit.h>

@interface CustomSegment : UIView
@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, assign) NSInteger segments;
@property (nonatomic, strong) NSArray *touchDownImages;
@property (nonatomic, readonly, assign) NSInteger selectedIndex;
@property (nonatomic, weak) id delegate;


- (id)initWithPoint:(CGPoint)point numberOfSegments:(NSInteger)_segments andTouchDownImages:(NSArray *)_touchDownImages;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
@end
Run Code Online (Sandbox Code Playgroud)

.M

#import "CustomSegment.h"

@implementation CustomSegment
@synthesize bgImageView, segments, touchDownImages, selectedIndex, delegate;

- (id)initWithPoint:(CGPoint)point
   numberOfSegments:(NSInteger)_segments
           andTouchDownImages:(NSArray *)_touchDownImages  
{  
    self = …
Run Code Online (Sandbox Code Playgroud)

iphone uitouch uicontrol ios

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

隐藏/显示UIPickerView

我有一个touchesEnded事件,用于检查何时按下UITextField.我想要它做的是隐藏/显示UIPickerView.如何才能做到这一点?

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view]))
    {
        NSString * error = @"Touched the TextField";
        UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Selection!" message:error delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
        //Want to show or hide UIPickerView
    }
}
Run Code Online (Sandbox Code Playgroud)

触摸发生时我已经分配了UIPickerView

@interface ThirdViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate> {
    IBOutlet UIPickerView *pickerView;
}
Run Code Online (Sandbox Code Playgroud)

iphone uipickerview

19
推荐指数
4
解决办法
4万
查看次数

如何将进度条控件添加到Matlab gui?

是否有现成的进度条uicontrol可以添加到Matlab gui,uicontrol或ActiveX组件?

[edit]我知道waitbar函数,我的意思是一个可以在设计的GUI中实现的组件,而不仅仅是弹出窗口.状态栏中的电池状态.

matlab user-interface uicomponents

18
推荐指数
2
解决办法
3万
查看次数

使用jQuery从clicked元素获取最接近的输入值

我有以下标记:

<div class="options">
  <div class="quantity">
     <label>Qty:</label>
     <input type="text" name="quantity" value="1"/>
  </div>
  <div class="buttons">
    <a href="#" class="add">Add Item</a>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我有一个使用jQuery绑定到'add'类的click事件.当我点击它时,我想得到name ="quantity"的值,但是有几个地方点击了'add'和几个数量字段.

我正试图获得'最接近'的输入值.我尝试过使用'最近'和'findall',但没有运气.

知道如何使用jQuery获得这个吗?谢谢!

javascript jquery

17
推荐指数
2
解决办法
4万
查看次数

在不同的swift版本中找不到sizeForItemAtIndexPath

我正在使用UICollectionView但未找到以下方法:

 func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
Run Code Online (Sandbox Code Playgroud)

请建议我替换它.

uicollectionview uicollectionviewlayout swift swift3 swift4

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

加密视频文件?

我正在使用此方法加密视频文件:

public static void encryptToBinaryFile(String password, byte[] bytes, File file) throws EncrypterException {
    try {
        final byte[] rawKey = getRawKey(password.getBytes());
        final FileOutputStream ostream = new FileOutputStream(file, false);

        ostream.write(encrypt(rawKey, bytes));
        ostream.flush();
        ostream.close();

    } catch (IOException e) {
        throw new EncrypterException(e);
    }
}

private static byte[] encrypt(byte[] raw, byte[] clear) throws EncrypterException {
    try {
       final SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
       final Cipher cipher = Cipher.getInstance("AES");
       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

       return cipher.doFinal(clear);

    } catch (Exception e) {
        throw new EncrypterException(e);
    }
}
Run Code Online (Sandbox Code Playgroud)

但它给出了一个错误Outofmemoryerror说拒绝分配301023321元素. …

java encryption android file out-of-memory

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