I'm implementing a digital signature in my application using Objective c, but when I tap the screen and drag the finger, the line is cut in two.
This is the code:
UIScrollView *contenido = [[UIScrollView alloc] init];
contenido.bounces = NO;
DBSignatureView *vistaFirma = [[DBSignatureView alloc] initWithFrame:CGRectMake(0, y, (margen-5) , tamCelda=tamCanvas)];
[
[![enter image description here][1]][1]vistaFirma addGestureRecognizer:gestureRecognizer];
vistaFirma.userInteractionEnabled = NO;
vistaFirma.layer.borderColor = [UIColor colorWithWhite:1.0f alpha:1.0f].CGColor;
vistaFirma.layer.borderWidth = 1.0f;
[contenido insertSubview:vistaFirma atIndex:contenido.subviews.count-(contenido.subviews.count > 1 ? 1 : 0)];
Which property should I implement?
Related
I have a customed overlay view for my UIImagePickerController.
I want to add an UITapGestureRecognizer in this overlay view in order to draw a circle and focus the camera.
But once I added the gesture, my method is never called and I don't understand why.
Here is my code:
// Overlay view
UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
// TapGesture
UITapGestureRecognizer *stabilisateurGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(Stabiliser:)];
stabilisateurGesture.numberOfTapsRequired = 1;
[overlay addGestureRecognizer:stabilisateurGesture];
// UIImagePickerController
pickerCamera = [[UIImagePickerController alloc] init];
pickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerCamera.delegate = self;
pickerCamera.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
pickerCamera.modalPresentationStyle = UIModalPresentationFullScreen;
pickerCamera.showsCameraControls = NO;
pickerCamera.cameraOverlayView = overlay;
And here the gesture method:
- (void)Stabiliser:(UITapGestureRecognizer *)gesture {
CGPoint point = [gesture locationInView:gesture.view];
// Create circle
UIView *cercleRouge = [[UIView alloc] initWithFrame:CGRectMake(point.x-(86/2), point.y-(86/2), 86, 86)];
cercleRouge.layer.borderColor = [[UIColor redColor] CGColor];
cercleRouge.layer.borderWidth = 4;
cercleRouge.layer.cornerRadius = cercleRouge.frame.size.height/2;
[gesture.view addSubview:cercleRouge];
}
Thank you in advance.
I have a UIView called loadingView shows some UIActivityIndicatorView-like animation. There are two UIViewControllers that all have such UIView.
The initial UIViewController's code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Also it has a button to present the second UIViewController:
- (void)buttonPressed {
SecondViewController *sVC = [[SecondViewController alloc] init];
[self presentViewController:sVC animated:YES completion:nil];
}
The second ViewController's viewDidLoad method code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
As you can see, the two UIViewControllers has the same viewDidLoad method code.
The loadingView works well in the initial UIViewController.
But in the second UIViewController, the loadingView only displays the black frame( I set the background colour to black).
Here is my loadingView implement code:
#define NUMBER_OF_DOT 15
#define DURATION 1.5
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.replicatorLayer = [[CAReplicatorLayer alloc] init];
self.replicatorLayer.frame = frame;
self.replicatorLayer.cornerRadius = 10.0;
self.replicatorLayer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.86].CGColor;
self.replicatorLayer.position = self.center;
self.replicatorLayer.instanceDelay = DURATION/NUMBER_OF_DOT;
[self.layer addSublayer:self.replicatorLayer];
float size = frame.size.width*14/200;
self.dot = [[CALayer alloc] init];
self.dot.bounds = CGRectMake(0, 0, size, size);
self.dot.position = CGPointMake(frame.size.width/2, frame.size.height/5);
self.dot.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
self.dot.borderColor = [UIColor whiteColor].CGColor;
self.dot.borderWidth = 1.0;
self.dot.cornerRadius = 1.5;
self.dot.transform = CATransform3DMakeScale(0.01, 0.01, 0.01);
[self.replicatorLayer addSublayer:self.dot];
self.replicatorLayer.instanceCount = NUMBER_OF_DOT;
float angle = 2*M_PI/NUMBER_OF_DOT;
self.replicatorLayer.instanceTransform = CATransform3DMakeRotation(angle, 0.0, 0.0, 0.1);
self.shrink = [[CABasicAnimation alloc] init];
self.shrink.keyPath = #"transform.scale";
self.shrink.fromValue = [NSNumber numberWithFloat:1.0];
self.shrink.toValue = [NSNumber numberWithFloat:0.1];
self.shrink.duration = DURATION;
self.shrink.repeatCount = INFINITY;
[self.dot addAnimation:self.shrink forKey:nil];
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Put this code in viewDidAppear of SecondViewController so it works in present mode as well.
-(id) init {
self = [super init];
CGSize wSize = [[CCDirector sharedDirector] viewSize];
CCSprite*imgBackground = [CCSprite spriteWithImageNamed:#"imgBackground.png"];
imgBackground.anchorPoint = ccp(0, 0);
[self addChild:imgBackground];
//adding the plus button
btnPlus = [CCButton buttonWithTitle:#"[ Plus ]" fontName:#"Georgia" fontSize:16.0f];
btnPlus.positionType = CCPositionTypeNormalized;
btnPlus.position = ccp(0.25f, 0.25f);
[btnPlus setTarget:self selector:#selector(btnPlusClicked)];
[self addChild:btnPlus];
btnMinus = [CCButton buttonWithTitle:#"[ Minus ]" fontName:#"Georgia" fontSize:16.0f];
btnMinus.positionType = CCPositionTypeNormalized;
btnMinus.position = ccp(0.75f, 0.25f);
[btnMinus setTarget:self selector:#selector(btnMinusClicked)];
[self addChild:btnMinus];
//view.scene = (SCNScene*)self.scene;
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 560)];
SCNBox* boxGeometry = [SCNBox boxWithWidth:10.0 height:10.0 length:10.0 chamferRadius:1.0];
dScene = [[SCNScene alloc] init];
node = [SCNNode nodeWithGeometry:boxGeometry];
//view = [[SCNView alloc] init];
//view.scene = dScene;
//overlay.backgroundColor = [UIColor colorWithWhite:1 alpha:.5];
//view = [[SCNView alloc] init];
//view.backgroundColor =[UIColor colorWithWhite:0 alpha:.5];
//[overlay addSubview:view];
[[[CCDirector sharedDirector] view] addSubview:overlay];
[dScene.rootNode addChildNode:node];
//[self.scene addChild:node];
//node.light = SCNLightTypeAmbient;
return self;
}
I am trying to add a 3d object using scenekit to a cocos2d project because scenekit looks promising.
However, I'm getting error
OpenGL error GL_INVALID_FRAMEBUFFER_OPERATION detected at CCRenderStateGLTransition 298
OpenGL error GL_INVALID_FRAMEBUFFER_OPERATION detected at CCRenderStateGLTransition 298
OpenGL error GL_INVALID_FRAMEBUFFER_OPERATION detected at CCRenderStateGLTransition 298
Anyone knows if it is possible to do so? Any advice would be grateful. Thanks!
I have this piece of code, which is in init.
This should be some swipe cell, which is created by UIScrollView and there is some another view (my own action view) below cell.
My problem: if I want swipe my cell, UIScrollView doesnt call delegate methods :-/
Any suggestions? thx
self.cellState = kCellStateClosed;
self.cellScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSWIPECELL_WIDTH, kSWIPECELL_HEIGHT)];
self.cellScrollView.delegate = self;
self.cellScrollView.showsHorizontalScrollIndicator = NO;
self.cellScrollView.scrollsToTop = NO;
self.cellScrollView.scrollEnabled = YES;
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(selectCell)];
self.longPressGestureRecognizer = [[PAPLongPressGestureRecognizer alloc] initWithTarget:self action:#selector(scrollViewPressed:)];
self.longPressGestureRecognizer.minimumPressDuration = 0.1;
[self.cellScrollView addGestureRecognizer:self.tapGestureRecognizer];
[self.cellScrollView addGestureRecognizer:self.longPressGestureRecognizer];
// Create the content view that will live in our scroll view
self.scrollViewContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSWIPECELL_WIDTH, kSWIPECELL_HEIGHT)];
self.scrollViewContentView.backgroundColor = [UIColor whiteColor];
[self.cellScrollView addSubview:self.scrollViewContentView];
// Add the cell scroll view to the cell
UIView *contentViewParent = [self.subviews firstObject];
NSArray *cellSubviews = [contentViewParent subviews];
[self insertSubview:self.cellScrollView atIndex:0];
for (UIView *subview in cellSubviews)
{
[self.scrollViewContentView addSubview:subview];
}
self.containingTableView.directionalLockEnabled = YES;
//alloc action view
self.actionView = [[PAPActionCellView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) andPages:[self createActionPages] parentCell:self];
[self.cellScrollView insertSubview:self.actionView belowSubview:self.scrollViewContentView];
What you are missing is to set the contentSize of your UIScrollView, when you set it to some bigger value than its bounds, it will start to scroll, i.e:
self.cellScrollView.contentSize = CGSizeMake(2* kSWIPECELL_WIDTH, kSWIPECELL_HEIGHT);
When I try and apply a cameraOverlayView to UIImagePickerController, it doesn't show up. I have read through some documentation on how to apply this, and my code all looks correct. If someone could explain why my overlay isn't starting, I would really appriciate it.
//Start the camera up
UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.backgroundColor = [UIColor whiteColor];
btnView.alpha = 0.3;
btnView.clipsToBounds = YES;
//Add a button to the overlay
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024)];
snapButton.backgroundColor = [UIColor blackColor];
[btnView addSubview:snapButton];
//Overlay button view
imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:imageViewPickerController
animated:NO
completion:NULL];
SOLUTION:
I found the solution: it was both merging in Visput's suggestion, and fguchelaar's. I then removed the btnView.alpha = 0.3 and replaced it with btnView.opaque = NO; and that did the trick. Messed around with colors and now my overlay is working perfectly.
Frame of your overlay view has zero size:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectZero];
Change it like this and you will see it:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024];
Update:
Also enable clipsToBounds flag: btnView.clipsToBounds = YES;